akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N, K;
    string S;
    cin >> N >> K >> S;

    // 連続して0か1が出現する人数を記録する
    vector<int> nums(1, 1);
    rep(si, 1, S.size()) {
        if (S[si-1] == S[si]) ++nums[nums.size()-1];
        else nums.push_back(1);
    }

    // 数え上げを簡単にするため、必要であれば「0人」を追加する
    if (S[0] == '0') nums.insert(nums.begin(), 0);
    if (S[S.size()-1] == '0') nums.push_back(0);
    if (nums.size() == 1) nums.insert(nums.begin(), 0);
    if (nums.size()%2 == 0) nums.push_back(0);

    // numsの累積和
    vector<int> sumNums(nums.size());
    sumNums[0] = nums[0];
    rep(i, 1, sumNums.size())
        sumNums[i] = sumNums[i-1] + nums[i];
    sumNums.insert(sumNums.begin(), 0);

    // K回以下の操作を行ったとき、1が連続して出現する人数を数え上げて最大値をとる
    int maxRes = 0;
    rep(ki, 0, K+1) {
        int len = 2*ki;
        int l = 1, r = l+len;
        for (; r < sumNums.size(); l+=2, r+=2) {
            int res = sumNums[r] - sumNums[l-1];
            maxRes = max(maxRes, res);
        }
    }

    cout << maxRes << "\n";
}

Measured memory_bytes: 1656
x1, y1, x2, y2 = map(int, input().split())

d1 = x2 - x1
d2 = y2 - y1

x3 = x2 - d2
y3 = y2 + d1

x4 = x3 - d1
y4 = y3 - d2

print('{} {} {} {}'.format(x3, y3, x4, y4))


Measured memory_bytes: 2940
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;

int main() {
	int w, h, n, xmin, xmax, ymin, ymax, mem;
	vector<int>x, y, a;
	cin >> w >> h >> n;
	for (int i = 0; i < n; i++) {
		cin >> mem;
		x.push_back(mem);
		cin >> mem;
		y.push_back(mem);
		cin >> mem;
		a.push_back(mem);
	}
	xmin = 0;
	ymin = 0;
	xmax = w;
	ymax = h;
	for (int i = 0; i < n; i++) {
		if (a[i] == 1)xmin = max(x[i], xmin);
		if (a[i] == 2)xmax = min(x[i], xmax);
		if (a[i] == 3)ymin = max(y[i], ymin);
		if (a[i] == 4)ymax = min(y[i], ymax);
//		cout << i << ' ' << xmin << ' ' << xmax << ' ' << ymin << ' ' << ymax << endl;
	}
	if (xmax <= xmin || ymax <= ymin)
		cout << 0 << endl;
	else cout << (xmax - xmin)*(ymax - ymin) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
ll x;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>x;
    
    ll a=x%11;
    
    if(a>0&&a<=6)cout<<x/11*2+1<<"\n";
    else if(x==0)cout<<0<<"\n";
    else if(a>=7&&a<=10) cout<<x/11*2+2<<"\n";
    else cout<<x/11*2<<"\n";
    
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1e9+7

using namespace std;

int main()
{
  ll a, b, x;
  cin >> a >> b >> x;
  cout << b / x - a / x + (a % x ? 0 : 1) << endl;
}


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

int main(){
  int n, mmax = 0;
  string s;
  map<char, int> mp;
  cin >> n >> s;
  for(int i = 0; i < n; i++){
    mp.clear();
    for(int j = 0; j < i; j++) if(mp[s[j]] == 0) mp[s[j]]++;
    for(int j = i; j < n; j++) if(mp[s[j]] == 1) mp[s[j]]++;
    int tmp = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
      if(itr->second == 2) tmp++;
    }
    mmax = max(mmax, tmp);
  }
  cout << mmax << endl;
  return 0;
}


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

#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d ",x)
#define pl(x)	printf("%lld ",x)
#define ps(s)	printf("%s ",s)

using namespace std;

int distance(int x1, int x2, int y1, int y2){
    
    return abs(x1 - x2) + abs(y1 - y2);
}



int main(){
        
    int n, m;
    cin >> n >> m;
    
    vector<pair<int, int>>a(n);
    vector<pair<int, int>>b(m);
    //cout << "A STARTS" << endl;
    for(int i = 0; i < n; i++){
        cin >> a[i].first >> a[i].second;
        //cout << a[i].first << " " << a[i].second << endl; 
    }
    //cout << "B STARTS" << endl;
    for(int i = 0; i < m; i++){
        cin >> b[i].first >> b[i].second;
        //cout << b[i].first << " " << b[i].second << endl;
    }
    
    int current, previous;
    for(int i = 0; i < n; i++){
        current = INT_MAX;
        previous = current;
        int x1 = a[i].first;
        int y1 = a[i].second;
        int idx = 1 << 20;
        int x2, y2;
        for(int j = 0; j < m; j++){
            x2 = b[j].first;
            y2 = b[j].second;
            
            //pi(x1); pi(x2); pi(y1); pi(y2); cout << endl;
            current = distance(x1, x2, y1, y2);
            //cout << "I : " << i << " J : " << j << " " << current << endl; 
            if(current < previous){
                previous = current;
                idx = j+1;
            }
            else if(current == previous){
                idx = min(idx, j+1);
            }
            
        }
        cout << idx << endl;
    }
    
    
    
    
    
    
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
  int main(){
    int n;
    cin>>n;
    int a[10000];
    for(int i=0;i<n;i++) cin>>a[i];

    int mn =a[0], mx =a[0];
    long long sum = 0;
    for(int i=0;i<n;i++){
       mn = min(mn,a[i]);
       mx = max(mx,a[i]);
       sum += a[i];
    }
    cout<<mn<<" "<<mx<<" "<<sum<<endl;

    return 0;
}


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

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

int main() {
    int N;
    string status;
    map<string, int> mp;
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["TLE"] = 0;
    mp["RE"] = 0;

    cin >> N;
    rep(i, N) {
        cin >> status;
        mp[status] += 1;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

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

		int k = sc.nextInt();
		int s = sc.nextInt();

		int ans = 0;

		for (int x = 0; x <= k; x++) {
			for (int y = 0; y <= k; y++) {
				int z = s - x - y;
				if (0 <= z && z <= k) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
	ll n,m;
	cin>>n>>m;
	ll a=llmin,b=llmax;
	rep(i,m){
		ll l,r;
		cin>>l>>r;
		a=max(a,l);
		b=min(b,r);
	}
	if (b-a+1>0){
		cout<<b-a+1<<endl;
	}
	else{
		cout<<0<<endl;
	}
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first 
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=1e9 + 7;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n<0)return 0;if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(),x.end()
#define Return(x) {cout << x << endl; return 0;}


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

    vi a(n,0);
    int s = 0;
    for(int i=0;i<n;i++) {cin >> a[i]; s += a[i];}
    int k = 0;
    for(int x:a) {
        if(4*m*x >= s) k++;
    }

    if(k >= m) cout << "Yes" ; else cout << "No";
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int dp[3005][3005][2],n,m;
P<int,int> a[3005];
int dfs(int p,int t,int f){
	if(dp[p][t][f]!=-1)return dp[p][t][f];
	if(p==n+1)return dp[p][t][f]=0;
	int re=dfs(p+1,t,f);
	if(t+a[p].F<=m){
		re=max(re,dfs(p+1,t+a[p].F,f)+a[p].S);
	}
	if(f){
		re=max(re,dfs(p+1,t,0)+a[p].S);
	}
	return dp[p][t][f]=re;
}
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	cin>>n>>m;m--;
	FOR(i,1,n){
		cin>>a[i].F>>a[i].S;
	}
	memset(dp,-1,sizeof(dp));
	cout<<dfs(1,0,1);
	return 0;
}





Measured memory_bytes: 71168
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int A,B,K;
    cin>>A>>B>>K;
    int X=min(A,B);
    vector<int> Y; //数の宣言なし
    for(int i=1;i<=X;i++){
        if(A%i==0 && B%i==0){
            Y.push_back(i);
        }
    }
    reverse(Y.begin(),Y.end());
    cout<<Y[K-1]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

lli body(lli a, lli b){
	return (a-b)*(a-b);
}
int main()
{
	map<lli, lli> a;
	lli n;
	cin >> n;
	rep(i,n){
		lli t;
		cin >> t;
		a[t] += 1;
	}
	for(const auto& x : a){
		if(x.second > 1){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
 	return 0;
}


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

int main(void){
    int dp[200][200],d,n,t[200],a[200],b[200],c[200],i,j,k,flag,ans;
    scanf("%d%d",&d,&n);
    for(i=0; i<d; i++){
        scanf("%d",&t[i]);
    }
    for(i=0; i<n; i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        if(t[0]>=a[i] && t[0]<=b[i]){
            dp[0][i]=0;
        }else{
            dp[0][i]=-1;
        }
    }
    for(i=1; i<d; i++){
        for(j=0; j<n; j++){
            // dp[i][j]????±??????????
            if(t[i]>=a[j] && t[i]<=b[j]){
                flag=0;
                for(k=0; k<n; k++){
                    if(flag==0){
                        if(dp[i-1][k]!=-1){
                            dp[i][j] = dp[i-1][k] + abs(c[j]-c[k]);
                            flag=1;
                        }
                    }else{
                        if(dp[i-1][k]!=-1){
                        ans = dp[i-1][k] + abs(c[j]-c[k]);
                            if(ans>dp[i][j]){
                                dp[i][j]=ans;
                            }
                        }
                    }
                }
            }else{
                dp[i][j] = -1;
            }
        }
    }
    d--;
    ans=dp[d][0];
    for(i=1; i<n; i++){
        if(ans<dp[d][i]){
            ans=dp[d][i];
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define pb push_back
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};


 
signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int A, B;
  cin >> A >> B;

  if (A > 8 || B > 8) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
def judge(A,M,X):
    flag = True
    for i in range(M):
        if A[i] < X:
            flag = False
            break
    return flag

if __name__ == "__main__":
    N,M,X = map(int,input().split())
    books = []
    b_comb = []
    
    for i in range(N):
        books.append([int(x) for x in input().split()])

    for i in range(2**N):
        skill = [0 for i in range(M)]
        cost = 0
        for j in range(N):
            if ((i >> j) & 1):
                cost += books[j][0]
                for k in range(1, M+1):
                    skill[k-1] += books[j][k]
        if judge(skill,M,X):
            b_comb.append(cost)

    if len(b_comb) != 0:
        print(min(b_comb))
    else:
        print('-1')

Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a, b;
    string ans = "Impossible";
    cin >> a >> b;
    if(a%3==0 || b%3==0 || (a+b)%3==0) ans = "Possible";
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=2e5+5;
vector<ll> adj[N];
ll node,dist;
void dfs(ll src,ll pr,ll d){
    if(d>=dist){
        node=src;
        dist=d;
    }
    for(auto &v:adj[src])if(v!=pr)dfs(v,src,d+1);
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=0,u,v;i<n-1;i++)cin>>u>>v,adj[u].push_back(v),adj[v].push_back(u);
    dfs(1,1,0);
    dist=0;
    dfs(node,node,0);

    if(dist%3==1)cout<<"Second";
    else cout<<"First";
}


Measured memory_bytes: 20608
#include<stdio.h>

void swap(int a[],int x,int y){
	int temp=a[x];
	a[x]=a[y];
	a[y]=temp;
	return;
}

int main(){
	char com[4];
	int a[3]={1,0,0};
	
	while(scanf("%s",com)!=EOF){
		swap(a,com[0]-'A',com[2]-'A');
	}
	
	for(int i=0;i<3;i++){
		if(a[i]==1){
			printf("%c\n",'A'+i);
		}
	}
	
	return 0;
}


Measured memory_bytes: 2036
#include<stdio.h>
int main(void){
    int n,x,i,j,k,c=0,u=0,e=0,a=0,g=0;
    while(1){
        scanf("%d %d",&n,&x);
        if(n==0&&x==0)break;
        g++;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                    if(x==i+j+k&&i!=j&&j!=k&&k!=i){
                        u++;
                        }

            }
        }


    }

    c=u/6;
    if(c==0&&n!=0&&x!=0||u==0){
            for(e=0;e<g;e++){
        printf("0\n");
            }
    }else if(c>0){printf("%d\n",c);}


    n=0,x=0,c=0,u=0,e=0,a=0,g=0;
    }

return 0;
}

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

string str;
int n;

int main() {
#ifdef HOME
	freopen("arc103c.in", "r", stdin);
	freopen("arc103c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int lst;

	cin >> str;
	n = str.size();
	str = "0" + str;

	for (int i = 0; i <= n; ++i)
		if (str[i] != str[n - i]) {
			cout << "-1\n";
			return 0; }
	if (str[1] == '0') {
		cout << "-1\n";
		return 0; }

	lst = 2;
	cout << "1 2\n";
	for (int i = 2; i < n; ++i) {
		cout << lst << ' ' << i + 1 << '\n';
		if (str[i] == '1')
			lst = i + 1; }

	return 0; }


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
  int A,B,C; cin>>A>>B>>C;
  if (A+B+1 >= C) cout << B+C <<endl;
  else cout << A + 2*B + 1 << endl;
}


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

typedef long long ll;
const int maxn=505;

vector<int>edge[maxn];

int main()
{
    ios::sync_with_stdio(false);
    int n,m,q,x,y,ans,pos;
    vector<int>temp;
    while(cin>>n>>m>>q){
        for(int i=0;i<m;i++){
            cin>>x>>y;
            edge[x].push_back(y);
        }
        for(int i=0;i<=n;i++){
            sort(edge[i].begin(),edge[i].end());
        }
        for(int i=0;i<q;i++){
            ans=0;
            cin>>x>>y;
            for(int j=x;j<=y;j++){
                pos=-1;
                if((int)edge[j].size()){
                    pos=lower_bound(edge[j].begin(),edge[j].end(),y)-edge[j].begin();
                    while(pos<(int)edge[j].size()&&edge[j][pos]==y){
                        pos++;
                    }
                    ans+=pos;
                }
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <queue>
using namespace std;
bool check(queue<int> q, long long middle,int k){
    int cnt = 0;
    long long tmp = 0;
    while(!q.empty()){
        if(middle < q.front()) return false;
        tmp += q.front();
        if(tmp <= middle) q.pop();
        else{
            tmp = 0;
            cnt++;
        }
    }
    cnt++;
    return (cnt <= k);
}
int main(void){
    int n,k; cin >> n >> k;
    queue<int> q;
    int xnum = 0;
    for(int i=0; i<n; ++i){
        int x; cin >> x;
        q.push(x);
        xnum =max(xnum,x);
    }
    long long first = 0, last = xnum*n/k+1;
    while(last - first > 1){
        long long middle = (long long)(first + last)/2;
        if(check(q,middle,k)) last = middle;
        else first = middle;
    }
    cout << last << endl;
    return 0;
}


Measured memory_bytes: 3744
#include<stdio.h>

int main()
{
	int z;
	char x,y,c;
	scanf("%c ", &x);
	scanf("%c", &y);
	scanf("%c", &c);
	if ( c!= '\n')
	{
		printf("-1");
	}
	else
	{
		z = (x-'0') * (y-'0');

		printf("%d", z );

	}
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int i, j;
    for (i = 0; i < 9; i++)
    {
        for (j = 0; j < 9; j++)
        {
            printf("%dx%d=%d\n", i+1, j+1, (i+1)*(j+1));
        }
    }
    return 0;
}

Measured memory_bytes: 524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue - 10;
	const long INFL = long.MaxValue - 10;
	const double EPS = 1e-8;
	const double PI = 3.1415926536;
	
	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
		/*
		StreamReader sr = new StreamReader(@"D:\Download\2017-pr-t1-in5.txt");
		StreamWriter sw = new StreamWriter(@"D:\prog\joi\1-5.txt");
		string[] line = sr.ReadLine().Split(' ');
		sr.Close();
		sw.Close();
		*/
		string S = cin.next();
		string[] d = new string[] { "dream", "dreamer", "erase", "eraser" };

		int now = 4;
		int idx = 0;
		for (int i = S.Length - 1; i >= 0; i--)
		{
			if (now == 4)
			{
				if (S[i] == 'm')
				{
					now = 0;
					idx = 3;
				}else if (S[i] == 'e')
				{
					now = 2;
					idx = 3;
				}else if(i >= 2 && S[i] == 'r' && S[i-1] == 'e' && S[i-2] == 'm')
				{
					now = 1;
					idx = 5;
				}
				else if (i >= 2 && S[i] == 'r' && S[i - 1] == 'e' && S[i - 2] == 's')
				{
					now = 3;
					idx = 4;
				}
				else
				{
					Console.WriteLine("NO");
					return;
				}
			}
			else
			{
				//Console.WriteLine("i:{2} now:{0} idx:{1}",now,idx,i);
				if(S[i] == d[now][idx])
				{
					idx--;
					if(idx < 0)
					{
						now = 4;
					}
				}
				else
				{
					Console.WriteLine("NO");
					return;
				}
			}
		}
		if(now != 4)
		{
			Console.WriteLine("NO");
			return;
		}
		Console.WriteLine("YES");
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 3416
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int ndigits = numDigits(N);
    int highest = N / pow(10, ndigits - 1);
    int lowest = N % 10;
    long[][] f = new long[10][10];
    for (int i = 1; i < 10; i++) {
      for (int j = 1; j < 10; j++) {
        if (i == j && i <= N) f[i][j]++;
        for (int d = 2; d < ndigits; d++) {
          f[i][j] += pow(10, d - 2);
        }
        if (i > highest) continue;
        if (i == highest) {
          f[i][j] += N / 10 - highest * pow(10, ndigits - 2);
          if (j <= lowest) f[i][j]++;
        } else {
          f[i][j] += pow(10, ndigits - 2);
        }
      }
    }
    long res = 0;
    for (int i = 1; i < 10; i++) {
      for (int j = 1; j < 10; j++) {
        res += f[i][j] * f[j][i];
      }
    }
    System.out.println(res);
  }

  private static int pow(int n, int a) {
    if (a <= 0) return 1;
    int r = 1;
    for (int i = 0; i < a; i++) r *= n;
    return r;
  }

  private static int numDigits(int n) {
    int d = 0;
    while (n > 0) {
      d++;
      n /= 10;
    }
    return d;
  }
}


Measured memory_bytes: 23124
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    N = int(input())
    li = []
    for i in range(N):
        li.append(int(input()))
    
    print(lcm_list(li))

main()

Measured memory_bytes: 5076
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
SUM = sum(A)
count = Counter(A)
Q = int(input())
for _ in range(Q):
    B, C = map(int,input().split())
    SUM += (C - B) * count[B]
    count[C] += count[B]
    count[B] = 0
    print(SUM)

Measured memory_bytes: 24188
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define M 100010

ll f(ll n){
	ll ans=0;
	for(ll i=1;i*i<=n;++i){
		for(ll j=1;j*j<=n;++j){
			ll a=n-i*i-j*j-i*j,b=i+j;
			// z^2+zb-a=0
			ll D=b*b+4*a;
			ll sq=sqrt(D);
			if(sq*sq!=D)continue;
			if(sq-b>=0 and (sq-b)>=2)ans++;
		}
	}
	return ans;
}
int main(){
    IOS;
     
 	ll n;cin>>n;
 	rep(i,1,n+1)cout<<f(i)<<"\n";
     
     
     
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

map<ll, int>  prime_factorization_map(ll x) {
  map<ll, int> res;
  for(ll i = 2; i*i <= x; ++i) {
    while(x % i == 0) {
      if(res.find(i) == res.end()) res[i] = 0;
      ++res[i];
      x /= i;
    }
  }
  if(x != 1) res[x] = 1;
  return res;
}

int main()
{
  ll n; cin >> n;
  auto primes = prime_factorization_map(n);
  ll ans = 0;
  vector<ll> num(1000);
  rep(i, 1000) num[i] = i*(i+1)/2;
  for(auto x : primes) {
    auto it = upper_bound(ALL(num), x.second);
    --it;
    ans += distance(num.begin(), it);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;
 

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a-c)*(b-d)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
ll a[1005],b[1005];
vector<int>pos[1000*1000+5];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		pos[a[i]].push_back(0);
	}
	for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++){
		if(a[i] == a[j]){
			puts("0"); return 0;
		}
	}
	for(int i=1;i<=m;i++){
		scanf("%lld",&b[i]);
		pos[b[i]].push_back(1);
	}
	for(int i=1;i<=m;i++) for(int j=i+1;j<=m;j++){
		if(b[i] == b[j]){
			puts("0"); return 0;
		}
	}
	ll ans = 1;
	ll A = 0, B = 0;
	for(int i=n*m;i>=1;i--){
		int aa = 0, bb = 0;
		for(int j=0;j<pos[i].size();j++){
			int t = pos[i][j];
			if(t == 0){
				aa++;
			}
			else{
				bb++;
			}
		}
		if(aa && bb);
		else if(aa){
			ans = ans*B%mod;
		}
		else if(bb){
			ans = ans*A%mod;
		}
		else{
			ans = ans*(A*B-(n*m-i))%mod;
		}
		A += aa;
		B += bb;
	}
	cout<<(ans%mod+mod)%mod<<endl;
}

Measured memory_bytes: 23808
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
cin>>n;
ll l,r;
ll sum=0;
for(int i=0;i<n;i++){
    cin>>l>>r;
    sum+=r-l+1;
}
cout<<sum<<endl;
}












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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll n;
  cin >> n;

  cout << 180 * (n - 2) << "\n";
}

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

int main()
{
	std::string S;
	int N, K;
	std::cin >> N >> S >> K;

	char c = S[K - 1];

	for ( int i = 0; i < S.length(); i++ )
	{
		if ( S[i] != c )
		{
			S[i] = '*';
		}
	}

	std::cout << S << std::endl;

	return ( 0 );
}


Measured memory_bytes: 888
import numpy as np
N,M,C = list(map(int,input().split()))
B = list(map(int,input().split()))
#print(N,M,C,B)
ans = 0
for i in range(N):
  A = []
  A = list(map(int,input().split()))
  if (np.dot(A,B)+C)>0 :
    ans+=1
print(ans)

Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
const ll mod=1e9+7;
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const ll N=1e6+8;
ll dp[N];
ll a[N];
int main(){
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
	}
	for(ll i=0;i<N;i++)
	dp[i]=INT_MAX;
	dp[1]=0;
   for(ll i=1;i<n;i++){
   	for(ll j=i+1;j<=i+2;j++){
   		dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
   		//cout<<dp[j]<<endl;
	   }
   }
   cout<<dp[n]<<endl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;

vi normarize(const vi &v)
{
    vector<vi> r(4);
    rep(i,4)
    {
        vi t(4);
        rep(j,4) t[j]=v[(i+j)%4];
        r[i]=t;
    }
    sort(all(r));
    return r[0];
}

inline ll P(int n, int r)
{
    if(n<r) return 0;

    ll ret=1;
    rep(i,r) ret*=n-i;
    return ret;
}

inline ll POW(int x, int n)
{
    ll ret=1;
    rep(i,n) ret*=x;
    return ret;
}

inline ll DIM(const vi &v)
{
    if(v[0]==v[1] && v[1]==v[2] && v[2]==v[3]) return 4;
    else if(v[0]==v[2] && v[1]==v[3]) return 2;
    return 1;
}

int main()
{
    int n;
    scanf(" %d", &n);

    vector<vi> c(n,vi(4));
    rep(i,n)rep(j,4) scanf(" %d", &c[i][j]);

    map<vi,int> ct;
    rep(i,n)
    {
        c[i]=normarize(c[i]);
        if(ct.find(c[i])==ct.end()) ct[c[i]]=1;
        else ++ct[c[i]];
    }

    ll ans=0;
    // 上面i, 下面j
    rep(i,n)rep(j,i)
    {
        // 下面の向きを設定
        rep(k,4)
        {
            vi u(4);
            rep(x,4) u[x]=c[j][(k+x)%4];
            swap(u[1],u[3]);

            map<vi,int> sides_ct;
            rep(x,4)
            {
                vi t(4);
                t[0]=c[i][(x+1)%4];
                t[1]=c[i][x];
                t[2]=u[x];
                t[3]=u[(x+1)%4];
                t=normarize(t);

                if(sides_ct.find(t)==sides_ct.end()) sides_ct[t]=1;
                else ++sides_ct[t];
            }

            ll add=1;
            for(const auto &x:sides_ct)
            {
                vi key=x.fi;
                int value=x.se;

                // 使ってないタイルのうち当てはめられる個数
                int num=ct[key];
                if(c[i]==key) --num;
                if(c[j]==key) --num;

                // 選び方、向き、位置
                add*=P(num,value)*POW(DIM(key),value);
            }
            ans+=add;
        }
    }

    // 向かい合う面の個数ぶん重複する
    cout << ans/3 << endl;
    return 0;
}


Measured memory_bytes: 139904
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let (a, b, c, d) = (int(), int(), int(), int());
    println!("{}", max(a * b, c * d))
}


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

int main(){
    int n,k;
    cin>>n>>k;
    double ans = 0.00000000000;
    for(int i=1;i<=n;++i){
        for(int j=0;j<=30;++j){
            if(i*pow(2,j)>=k){
                ans+=1.0/n*pow(0.5,j);
                break;
            }
        }
    }
    cout<<fixed << setprecision(10) <<ans<<endl;
}

Measured memory_bytes: 256
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  string s;
  cin >> s;
  string prev = "" ;
  prev.pb(s[0]);
  ll ct = 1;
  for(ll i = 1; i < (ll)s.length(); i++) {
      if(prev.length() > 1) {
        prev = s[i] ;
        ct++ ;
      }
      else {
        if(s[i] != prev[0])  {
          ct++ ;
          prev = s[i];
        } 
        else {
            if(i!= (ll)s.length()-1) {
              ct++;
              prev.pb(s[i+1]);
              i++;
            }
        }
      }
  }
  cout << ct << endl;
  return 0;
} //good night.

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
string s;
int res;
int main()
{
	cin >>s;
	for (int i=0;i<s.size()/2;i++)
		if (s[i]!=s[s.size()-1-i]) res++;
	cout <<res;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,p;
int a[10],b[10];
int main()
{
    scanf("%d%d",&n,&p);
    for(int i=0;i<n;i++)
        scanf("%d%d",&a[i],&b[i]);
    int ans=1e9;
    for(int i=0;i<(1<<n);i++)
    {
        int sum=0,res=0;
        for(int j=0;j<n;j++)
            if((1<<j)&i)
            {
                res+=a[j];
                sum+=(j+1)*100*a[j]+b[j];
            }
        for(int j=n-1;j>=0&&sum<p;j--)
        {
            if((1<<j)&i) continue;
            for(int k=1;k<=a[j]&&sum<p;k++)
            {
                res++;
                sum+=100*(j+1);
                if(k==a[j]) sum+=b[j];
                if(sum>=p) break;
            }
            if(sum>=p) break;
        }
        if(sum>=p)
            ans=min(ans,res);
    }
    cout<<ans<<endl;
}


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

string S; int cnt = 0;

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'o') cnt++;
	}
	cnt += (15 - (int)S.size());
	if (cnt >= 8) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;

bool test(int[][] s, int n) {
	auto rect = new bool[](n+1);
	rect[n] = false;
	foreach(_; 0..n) {
		foreach(i; 0..n) {
			ulong xmin, ymin, xmax, ymax;
			xmin = s[0].length;
			ymin = s.length;
			xmax = 0;
			ymax = 0;
			foreach(j; 0..s.length) {
				foreach(k; 0..s[0].length) {
					if(s[j][k] == i) {
						xmin = min(xmin, k);
						ymin = min(ymin, j);
						xmax = max(xmax, k);
						ymax = max(ymax, j);
					}
				}
			}
			bool f = true;
			if(xmax >= xmin && ymax >= ymin) {
				foreach(j; ymin..ymax+1) {
					foreach(k; xmin..xmax+1) {
						f &= s[j][k] == i || rect[s[j][k]];
					}
				}
				rect[i] |= f;
			}
		}
	}
	rect[n] = true;
	return !n || reduce!("a&&b")(rect);
}

void main() {
	int n = to!int(readln().strip());
	foreach(_; 0..n) {
		auto hw = map!(to!int)(readln().strip().split());
		int h = hw[0];
		int w = hw[1];
		string[] s;
		int[char] c;
		int cn;
		foreach(i; 0..h) {
			s ~= readln().strip();
		}
		foreach(i; 0..h) {
			foreach(j; 0..w) {
				if(s[i][j] != '.' && s[i][j] !in c)
					c[s[i][j]] = cn++;
			}
		}
		c['.'] = cn;
		auto t = new int[][](h,w);
		foreach(i; 0..h) {
			foreach(j; 0..w) {
				t[i][j] = c[s[i][j]];
			}
		}
		writeln(test(t, cn)?"SAFE":"SUSPICIOUS");
	}
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) ((x)==0?0:__builtin_popcount(x))

#define INF 1e16
#define mod 1000000007

int n;
int a[10],b[10],c[10];

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

  int S=0;
  rep(T,1<<n){
    if(bcnt(T)<=1)continue;
    int pairnum=0;
    rep(i,n)rep(j,i){
      if(((T>>i)&1)&&((T>>j)&1)){
        b[pairnum]|=1<<S;
      }
      pairnum++;
    }
    rep(i,n)if((T>>i)&1)c[i]|=1<<S;
    S++;
  }
  ll res=INF;
  rep(T,1<<S){
    bool ok=true;
    rep(i,n*(n-1)/2){
      if(bcnt(T&b[i])>1){
        ok=false;
        break;
      }
    }
    if(!ok)continue;
    ll sum=0;
    rep(i,n){
      if(bcnt(T&c[i])>a[i]){
        ok=false;
        break;
      }
      sum+=a[i]-bcnt(T&c[i]);
    }
    if(!ok)continue;
    minch(res,sum+bcnt(T));
  }
  cout<<res<<endl;
  return 0;
}



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

const int MAXN = 1e5+10;
struct Edge
{
    int to,next;
}edge[MAXN*2];
int head[MAXN];
int tot;
int col[MAXN];
long long c1,c2;
bool flag;

void addedge(int u, int v)
{
    edge[tot].to = v;
    edge[tot].next = head[u];
    head[u] = tot++;
}

void dfs(int u, int color)
{
    if(flag) return;
    col[u] = color;
    if(color == 1)
        ++c1;
    else
        ++c2;
    for(int i = head[u]; i != -1; i = edge[i].next)
    {
        int v = edge[i].to;
        if(!col[v])
            dfs(v,3-color);
        else if(col[v] == color)
        {
            flag = true;
            return;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    long long n,m;
    cin >> n >> m;
    int u,v;
    memset(head,-1,sizeof(head));
    memset(col,0,sizeof(col));
    c1 = c2 = tot = 0;
    flag = false;
    for(int i = 0; i < m; ++i)
    {
        cin >> u >> v;
        addedge(u,v);
        addedge(v,u);
    }
    dfs(1,1);
    if(flag)
        cout << n*(n-1)/2-m;
    else
        cout << c1*c2-m << endl;
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,c1=0,c2=0,c3=0,c=1;
  cin>>n;
  if(n%2==0)
  {
      for(long long int i=1;i<=n/2;i++)
   {
      if(i%3==0 || i%5==0 || i%3==0 && i%5==0)
        continue;
      else
        c1+=i;
   }
   for(long long int j=(n/2)+1;j<=n;j++)
   {
     if(j%3==0 || j%5==0 || j%3==0 && j%5==0)
        continue;
      else
        c2+=j;
   }
   cout<<c1+c2;

  }


  if(n%2!=0)
  {
      for(long long int i=1;i<=n/2;i++)
   {
      if(i%3==0 || i%5==0 || i%3==0 && i%5==0)
        continue;
      else
        c1+=i;
   }
   for(long long int j=(n/2)+1;j<=n;j++)
   {
     if(j%3==0 || j%5==0 || j%3==0 && j%5==0)
        continue;
      else
        c2+=j;
   }
   cout<<c1+c2;

  }
  return 0;



}


Measured memory_bytes: 3576
x1,y1,x2,y2=map(int,input().split())
dx=x2-x1
dy=y2-y1
(dx,dy)=(-dy,dx)
x3=x2+dx
y3=y2+dy
(dx,dy)=(-dy,dx)
x4=x3+dx
y4=y3+dy
print(x3,y3,x4,y4)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
#include <vector>
#include <map>
using namespace std;
#define rep(k, n) for(int i=k;i< n;i++)
#define LL long long int
#define L long
#define INF numeric_limits<int>::max() // double INF numeric_limits<double>::infinity()

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
    int n;cin>>n;
    int v[n];
    rep(0, n)cin>> v[i];
    int dp[n];
    dp[0]= 0;dp[1]= abs(v[0]-v[1]);
    rep(2, n)dp[i]= INF;
    rep(2, n){
        dp[i]= min(dp[i], min(dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+ abs(v[i]-v[i-2])));
    }
    cout<< dp[n-1];
}


Measured memory_bytes: 4344
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef struct {
	string s;
	int p;
	int i;
}Restaurant;

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

	int n;
	cin >> n;
	vector<Restaurant> res(n);
	for (int i = 0; i < n; i++) {
		cin >> res[i].s >> res[i].p;
		res[i].i = i + 1;
	}

	sort(res.begin(), res.end(), [](Restaurant& a, Restaurant& b) {
		if (a.s == b.s) {
			return a.p > b.p;
		}
		else {
			return a.s < b.s;
		}
		});
	for (int i = 0; i < n; i++) {
		cout << res[i].i << endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
int n,a[(1<<19)+1];
bool leaf[(1<<19)+1];
ll ans,b[(1<<19)+1],c[(1<<19)+1];
vector<int>wait,tmp;
void dfs(int x,ll s,int g)
{
	tmp.push_back(x);
	if(x>=n)
	{
		wait.push_back(a[x-n+1]+n-1);
		if(g)
			b[a[x-n+1]+n-1]=s*(a[x-n+1]+n-1)%mod;
		else
			c[a[x-n+1]+n-1]=s*(a[x-n+1]+n-1)%mod;
		tmp.push_back(a[x-n+1]+n-1);
		return;
	}
	assert(s>=0);
	dfs(x<<1,s*(x<<1)%mod,g);
	dfs(x<<1|1,s*(x<<1|1)%mod,g);
}
inline void solve(ll x)
{
	dfs(x<<1,x<<1,0);
	for(int i=0;i<wait.size();++i)
	{
		int u=wait[i];
		ll now=c[u];
		tmp.push_back(u);
		u>>=1;
		while(u)
		{
			tmp.push_back(u);
			now=now*u%mod;
			c[u]=(c[u]+now)%mod;
			u>>=1;
		}
	}
	wait.clear();
	dfs(x<<1|1,(x<<1|1)*x%mod,1);
	for(int i=0;i<wait.size();++i)
	{
		int u=wait[i];
		ll now=b[u];
		while(u!=1)
		{
			ans=(ans+now*c[u^1]%mod*(u>>1)%mod)%mod;
			u>>=1;
			now=now*u%mod;
		}
	}
	wait.clear();
	for(int i=0;i<tmp.size();++i)
		c[tmp[i]]=b[tmp[i]]=0;
	tmp.clear();
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	n=1<<(n-1);
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=n-1;++i)
		solve(i);
	cout<<(ans%mod+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 14628
def judge(a):
    if a%2 == 0:
        n = a/2
    else:
        n = 3*a+1
    return(int(n))
list=[]
x=int(input())
list.append(x)
for i in range(100000):
    b = judge(x)
    if (b in list) == True:
        print(i+2)
        break
    else:
        list.append(b)
        x = b

Measured memory_bytes: 3060
S = input()
Sl = [i for i in S]
Slen = len(Sl)
Cv = S.find("C")
C = Sl.pop(Cv)
A = Sl.pop(0)
lo = "".join(Sl)

if A == "A" \
and C == "C" \
and lo.islower() == True \
and 2 <= Cv < (Slen-1):
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
#include<cstdio>

int main(){
    int count[1201];
    // for(int i = 0; i < 1201; i++){
    //     count[i] = 0;
 	// }
    char ch;
    while(scanf("%c",&ch) != EOF){
        if(ch >= 'a' && ch <= 'z'){
            count[ch-'a']++;
        }
        else if(ch >= 'A' && ch <= 'Z'){
            count[ch-'A']++;
        }
    }
    for(int j = 0;j < 26; j++){
        printf("%c : %d\n",j + 'a',count[j]);
    }
    return 0;
}


Measured memory_bytes: 2704