akhauriyash/Code-Regression huggingface dataset:
MOD = 10**9 + 7

def prod(a):
    res = 1
    for x in a:
        res = (res * x) % MOD
    return res

def solve(n, k, a):
    if k == 1:
        return max(a)
    elif k == n:
        return prod(a)
    elif (max(a) < 0) and (k % 2 == 1):
        a = sorted(a, reverse=True)
        return prod(a[:k])
    else:
        a = sorted(a, key=lambda x: -abs(x))
        num_negative = len(list(filter(lambda x: x < 0, a[:k])))
        if num_negative % 2 == 0:
            return prod(a[:k])
        else:
            i1, j1 = None, None
            for i in range(k):
                if a[i] < 0:
                    i1 = i
            for j in range(k,n):
                if a[j] >= 0:
                    j1 = j
                    break
            i2, j2 = None, None
            for i in range(k):
                if a[i] >= 0:
                    i2 = i
            for j in range(k, n):
                if a[j] < 0:
                    j2 = j
                    break
            if ((i1 is None) or (j1 is None)) and ((i2 is None) or (j2 is None)):
                return prod(a[:k])
            elif (i1 is None) or (j1 is None):
                return prod(a[:i2] + a[i2+1:k] + [a[j2]])
            elif (i2 is None) or (j2 is None):
                return prod(a[:i1] + a[i1+1:k] + [a[j1]])
            elif abs(a[j1] * a[i2]) > abs(a[i1] * a[j2]):
                return prod(a[:i1] + a[i1+1:k] + [a[j1]])
            else:
                return prod(a[:i2] + a[i2+1:k] + [a[j2]])

n, k = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, k, a))

Measured memory_bytes: 31848
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll n,ww; cin>>n>>ww;
  vector<vector<ll>> dp(n+1,vector<ll>(ww+1));
  vector<ll> v(n+1),w(n+1);
  rep(i,n) cin>>w[i+1]>>v[i+1];
  REP(i,1,n+1){
    REP(j,1,ww+1){
      if(j < w[i]) dp[i][j] = dp[i-1][j];
      else dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
    }
  }
  cout<<dp[n][ww]<<endl;
}

Measured memory_bytes: 83084
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(int i = 0; i<(int)rept;++i)
typedef long long ll;
using namespace std;


int main() {
	//16日目 
	//尺取り法

	int n;
	cin >> n;
	string s;
	cin >> s;
	int c = 0;
	for (int i = 1; i<n; i++) {
		if (s[i] == 'E')c++;
	}
	int ans = c;
	for (int i = 1; i<n; i++) {
		if (s[i] == 'E')c--;
		if (s[i - 1] == 'W')c++;
		ans = min(ans, c);
	}
	cout << ans << endl;
	return 0;

}


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

int main() {
  int N; cin >> N; vector<int> X(N); int total =0;
  for (int i =0; i<N; i++) {cin >> X.at(i); total += X.at(i);}
  sort(X.begin(),X.end());
  int aveL = total/N ; int aveR = aveL + 1; int ansL =0; int ansR = 0;
  for (int i =0; i<N; i++) {
    ansL += (X.at(i) - aveL) * (X.at(i) - aveL); ansR += (X.at(i) - aveR) * (X.at(i) - aveR);
  }
  cout << min(ansL,ansR) << endl;
}

Measured memory_bytes: 3628
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var tmp = line[0].split(" ");
	var a = Number(tmp[0]);
	var b = Number(tmp[1]);
	console.log(Math.ceil((a+b)/2));
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;

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

	int n;
	string s;
	cin >> n >> s;
	
	vector<int> east(n), west(n);
	west[0] = (s[0] == 'W');
	for (int i = 1; i < n; i++)
		west[i] = west[i-1] + (s[i] == 'W');
	east[n-1] = (s[n-1] == 'E');
	for (int i = n-2; i >= 0; i--)
		east[i] = east[i+1] + (s[i] == 'E');
	
	int best = min(east[1], west[n-2]);
	for (int i = 1; i < n-1; i++)
		best = min(best, west[i-1] + east[i+1]);
		
	cout << best << endl;
}


Measured memory_bytes: 2964
from sys import stdin
def main(pS):
    ans = {}
    ac = 0
    wa = 0
    for i in pS:
        if i[0] not in ans.keys():
            ans[i[0]] = [0, 0] 
        if i[1] == "AC":
            if ans[i[0]][0] == 0:
                    ans[i[0]][0] += 1
                    ac += 1
                    wa += ans[i[0]][1]
        elif i[1] == "WA":
            if ans[i[0]][0] == 0:
                ans[i[0]][1] += 1
    return [ac, wa]

"""
for i in ans.values():
    ac += i[0]
    if i[0] >= 1:
        wa += i[1]
"""
if __name__ == "__main__":
    N, M = input().split()
    pS = [stdin.readline().rstrip().split() for _ in range(int(M))]
    ac, wa = main(pS)
    print(ac, wa)

Measured memory_bytes: 49616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int n, m, c; cin >> n >> m >> c;
    vector<int> B(m);
    for (int i = 0; i < m; i++) {
        cin >> B[i];
    }
    vector<vector<int>> A(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int x = 0;
        for (int j = 0; j < m; j++) {
            x += A[i][j] * B[j];
        }
        if (x + c > 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
using ll = long long;
using ld = long double;

const int tinf=1e9;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin >> h >> w;
    int ch,cw,dh,dw;
    cin >> ch >> cw >> dh >> dw;
    int c=(ch-1)*w+(cw-1);
    int d=(dh-1)*w+(dw-1);

    vector<bool> s(h*w);
    for(int i = 0; i < h; i++) {
        string tmp;
        cin >> tmp;
        for(int j = 0; j < w; j++) {
            if(tmp[j]=='#') s[i*w+j]=false;
            else s[i*w+j]=true;
        }
    }

    vector<int> warp(h*w,tinf);
    deque<int> q;
    q.push_front(c);
    warp[c]=0;

    int wr[20]={-2,-2,-2,-2,-2,-1,-1,-1,-1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2};
    int wc[20]={-2,-1, 0, 1, 2,-2,-1, 1, 2,-2, 2,-2,-1, 1, 2,-2,-1, 0, 1, 2};

    int dr[4]={1,-1,0,0};
    int dc[4]={0,0,1,-1};

    while(!q.empty()) {
        int v=q.front();
        q.pop_front();
        int r=v/w;
        int c=v%w;

        for(int i = 0; i < 4; i++) {
            int nr=r+dr[i];
            int nc=c+dc[i];
            int nv=nr*w+nc;
            if(nr<0||nr>=h||nc<0||nc>=w||s[nv]==false) continue;
            if(warp[nv]>warp[v]){
                warp[nv]=warp[v];
                q.push_front(nv);
            }
        }

        for(int i = 0; i < 20; i++) {
            int nr=r+wr[i];
            int nc=c+wc[i];
            int nv=nr*w+nc;
            if(nr<0||nr>=h||nc<0||nc>=w||s[nv]==false) continue;
            if(warp[nv]>warp[v]+1){
                warp[nv]=warp[v]+1;
                q.push_back(nv);
            }
        }
        if(warp[d]==0) break;
    }

    if(warp[d]==tinf) cout << "-1" << "\n";
    else cout << warp[d] << "\n";

    return 0;
}

Measured memory_bytes: 7364
a = list(map(int,list(input())))

for i in range(2<<3):
    ans = a[0]
    st = str(a[0])
    for j in range(3):
        if (i>>j)&1 == 1:
            ans += a[j+1]
            st += "+"+str(a[j+1])
        else:
            ans += -a[j+1]
            st += "-"+str(a[j+1])
    if ans == 7:
        print(st+"=7")
        break

Measured memory_bytes: 38384
#include "bits/stdc++.h"

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 998244353;
const int NMAX = 1000*1000 + 11;

int arr[NMAX];
int n,m,p,q,k,a,b,c,ans;
string s,str;
char ch;
vector<int> v;
int f[NMAX];

int power(int x, unsigned int y, int p = MOD)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  

int nCr(int n, int r){
    int num = f[n];
    int den = power(f[n-r],MOD-2);
    int den2 = power(f[r],MOD-2);

    num = (num*den)%MOD;

    return (num*den2)%MOD;
}

void solve()
{
    cin>>n>>m>>k;
    int j =1;
    int ans = 0;
    f[0] = 1;
    for(int i=1;i<=n;i++){
        f[i] = (f[i-1]*i)%MOD;
    }

    if(n == 1){
        cout<<m;
        return;
    }

    if(m == 1 and k == n-1){
        cout<<1;
        return;
    }

    for(int i=n-1; i>=n-1-k; i--){
        // tr(n-1,j-1);
        ans += (m*((nCr(n-1,j-1)*power(m-1,n-j))%MOD))%MOD;
        // cout<<ans<<" ";
        ans %= MOD;
        j++;
    }
    cout<<ans;
}

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 5112
Q, H, S, D = map(int, input().split())
N = int(input())

min_1l = min([4 * Q, 2 * H, 1 * S])
min_2l = min([8 * Q, 4 * H, 2 * S, D])

ans = 0
if min_2l == D:
  ans = D * (N // 2) + (N % 2) * min_1l
else:
  ans = N * min_1l

print(ans)


Measured memory_bytes: 61864
#include<cstdio>
#include<cmath>

double rad=90.00000000000;//回転角
double x=0.0,y=0.0;//現在地
int answer_x,answer_y;
double PI=6*asin( 0.5 )/180;

int main()
{
	int a,b;
	while(scanf("%d,%d",&a,&b)!=EOF)
	{
		if(a==0&&b==0)break;
		y+=sin(rad*PI)*a;
		x+=cos(rad*PI)*a;
		rad=(rad-b);
	}
	if(x>0)answer_x=floor(x);
	else answer_x=ceil(x);
	if(y>0)answer_y=floor(y);
	else answer_y=ceil(y);
	printf("%d\n%d\n",answer_x,answer_y);
	return 0;
}

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

int main() {
	//入力
	int n;
	cin >> n;
	int a[100000];
	for (int i = 0; i < n; i++) cin >> a[i];

	//計算、出力
	int s = 1;
	for (int i = 0; i < n; i++) {
		s = a[s - 1];

		if (s == 2) {
			cout << i + 1 << endl;
			break;
		}
		if (i == n - 1) cout << -1 << endl;
	}

	return 0;
}

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

using namespace std;

const int MAXN = 1e5 + 5;

const long long int MAXMIN = 1e17;

long long int a[MAXN];

int main() {
	long long int n, k, minimum = MAXMIN;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - k + 1; i++)
		minimum = min(minimum, min(abs(a[i]), abs(a[i + k - 1])) + a[i + k - 1] - a[i]);
	cout << minimum;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

int h, w,k;
char board[50][50];
char sand[50][50];
char nsand[50][50];
void drop()
{
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			nsand[i][j] = ' ';
		}
	}
	for (int col = 0; col < w; ++col)
	{
		int cnt = h - 1;
		for (int y = h - 1; y >= 0; --y)
		{
			if (sand[y][col] != ' ')
			{
				nsand[cnt][col] = sand[y][col];
				--cnt;
			}
		}
	}
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			sand[i][j] = nsand[i][j];
		}
	}
}
int crush()
{
	int point = 0;
	for (int row = 0; row < h; ++row)
	{
		for (int itr = 0; itr < w - 1; ++itr)
		{
			if (sand[row][itr] == sand[row][itr + 1] && sand[row][itr] != ' ')
			{
				int itr2 = itr;
				while (sand[row][itr2] == sand[row][itr2 + 1])
				{
					itr2++;
				}
				if (itr2 - itr + 1 >= k)
				{
					point += (itr2 - itr + 1) * (sand[row][itr] - '0');
					for (int i = itr; i <= itr2; ++i)
					{
						sand[row][i] = ' ';
					}
				}
				itr = itr2;
			}
		}
	}
	return point;
}

int main(void)
{
	scanf("%d %d %d", &h, &w, &k);
	for (int i = 0; i < h; ++i)
	{
		scanf("%s",board[i]);
	}
	int answer = 0;
	for (int p = 0; p < h; ++p)
	{
		for (int q = 0; q < w; ++q)
		{
			for (int i = 0; i < h; ++i)
			{
				for (int j = 0; j < w; ++j)
				{
					sand[i][j] = board[i][j];
				}
			}
			int ans = 0;
			int tim = 1;
			sand[p][q] = ' ';
			drop();
			while (true)
			{
				int point = crush();
				if (point == 0)break;
				int score = point * tim;
				ans += score;
				drop();
				tim *= 2;
			}
			answer = max(answer,ans);
		}
	}
	printf("%d\n", answer);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
	#define ll long long int
	#define mod 1000000007
	#define rep(i,a,n) for (int i=a;i<n;i++)
	//rep(i,0,p) {
	using namespace std;

	void solve() {
		ll x,y,z;
		cin >> x>>y>>z;
		// ll arr[n];
		// rep(i,0,n){
		// 	cin >> arr[i];
		// }
		// ll one[n],two[n];
		// memset(one,0,sizeof(one));
		// memset(two,0,sizeof(two));
		// rep(i,0,n)
		cout << z<<" "<<x<<" "<<y<<"\n";
		return;

	}

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

		// int t;
		// cin >> t;
		// while(t--)
			solve();

	}

Measured memory_bytes: 256
//引退案件
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;


int main(void){
    ll n;
    cin>>n;
    cout<<n*800-(n/15)*200<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define debug(output) cout<<#output<<"= "<<output<<endl
using lint=long long;
int MOD=1000000007;

signed main(){
    int d,t,s;cin>>d>>t>>s;
	if(s*t>=d){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3600
k, n = map(int, input().split())
a = list(map(int, input().split()))

d = []
for i in range(n):
  if i != n-1:
    d.append(abs(a[i+1] - a[i]))
  else:
    d.append(abs(k - a[n-1] + a[0]))
d_max = max(d)

print(k - d_max)


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

typedef struct{
  int id;
  int d;
  int dd;
  int f;
  int k;
  int *A;
  int color;
} Point;

Point *p;
int n,i,j,id,t=0,*stack,x=0,top=0;

void insert(int u){
  stack[++top]=u;
}

void search(int u){
  int v;
  insert(u);
  p[u].color=0;
  p[u].d=++t;

  while(top!=0){
    u=stack[top];
    v=p[u].A[ p[u].f ];
    
    if(p[u].f<p[u].k){
      if(p[v].color==-1){
	p[v].color=0;
	p[v].d=++t;
	insert(v); }
    }
    else{
      top--;
      p[u].color=1;
      p[u].dd=++t;
    }
    
    p[u].f++;
    //printf("u=%d, v=%d, k=%d, f=%d, t=%d\n",u,v,p[u].f,p[u].k,t);
  }
  
}

int main(){

  scanf("%d",&n);

  p = (Point *) malloc (sizeof( Point )*n);

  for(i=0;i<n;i++){
    scanf("%d%d",&p[i].id,&p[i].k);
    
    p[i].A=(int *)malloc(sizeof(int) * p[i].k);
    top+=p[i].k;

    p[i].f=0;
    p[i].color=-1;
    
    for(j=0;j<p[i].k;j++){
      //printf("x=%d, k=%d --",x++,p[i].k);
      scanf("%d",&p[i].A[j]);
      p[i].A[j]--;
      
      //printf(" p[%d].A[%d]=%d ||",i,j,p[i].A[j]);
    }
    //printf("\n");
    
  }

  stack=(int *)malloc(sizeof(int)*top);
  top=0;

  for(i=0;i<n;i++) if(p[i].color==-1) search(i);
  for(i=0;i<n;i++) printf("%d %d %d\n",p[i].id,p[i].d,p[i].dd);
  
  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main(){
    int n;
    int m, e, j;
    bool hund;
    while (~scanf("%d", &n)) {
        REP(i, n) {
            hund = false;
            scanf("%d%d%d", &m, &e, &j);
            if (m == 100 || e == 100 || j == 100) hund = true;
            if (hund || (m + e) / 2 >= 90 || (m + e + j) / 3 >= 80) {
                puts("A");
            } else if ((m + e + j) / 3 >= 70 || (m + e + j) / 3 >= 50 && (m >= 80 || e >= 80)) {
                puts("B");
            } else {
                puts("C");
            }
        }
    }

    return 0;
}




Measured memory_bytes: 3012
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)] #各ノードの親番号
        self.rank = [0] * (n) #各ノードのランク（木の高さ）
        self.root = [-1]*(n+1) # -（各ノードの属するグループの要素数）

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            node = [x]
            cur = node[0]
            while self.par[cur] != cur:
                cur = self.par[cur]
                node.append(self.par[cur])
            
            for n in node:
                self.par[n] = cur
            
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.root[x] += self.root[y]
            self.root[y] = self.root[x]
        else:
            self.par[y] = x
            self.root[x] += self.root[y]
            self.root[y] = self.root[x]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
                
    # グループ数
    def groupsize(self):
        cnt = 0
        for i,x in enumerate(self.par):
            if x == i:
                cnt += 1
        return cnt

    # xの属すグループの要素数
    def size(self, x):
        return -self.root[self.find(x)]
    
    # xの属すグループの要素リスト
    def members(self, x):
        ret = []
        rootNode = self.find(x)
        for i in range(len(self.par)):
            if self.find(i) == rootNode:
                ret.append(i)
        return ret
    
    # ルートノードのリストを取得
    def get_roots(self):
        ret = []
        for i,x in enumerate(self.par):
            if x==i:
                ret.append(i)
        return ret
    
    # 各グループ毎の要素リストを取得
    def all_members(self):
        roots = self.get_roots()
        namedict = {}
        for i,r in enumerate(roots):
            namedict[r] = i            
        ret = [[] for _ in range(len(roots))]
        for i in range(len(self.par)):
            p = namedict[self.find(i)]
            ret[p].append(i)
        return ret
            
    

N,M,K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]
CD = [list(map(int,input().split())) for _ in range(K)]
    
uf = UnionFind(N)
for a,b in AB:
    uf.union(a-1,b-1)
    
ans = [0]*N
 
for group in uf.all_members():
    L = len(group)-1
    for a in group:
        ans[a] = L
        
# friends = [0]*N
# brock = [0]*N
for a,b in AB:
    ans[a-1] -= 1
    ans[b-1] -= 1
 
for c,d in CD:
    if uf.same_check(c-1,d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1
 
print(*ans)
        
    
    
    
    
    
    
    

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

int main(){
	int a[10];
	cin >> a[0];
    a[1] = (a[0] % 1000) / 100;
    a[2] = (a[0] % 100) / 10;
    a[3] = a[0] % 10;
    a[0] = a[0] / 1000;
	int op1,op2,op3;
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				int sum=a[0];
				if(i==0){
					sum+=a[1];
				}else{
					sum-=a[1];
				}
				if(j==0){
					sum+=a[2];
				}else{
					sum-=a[2];
				}
				if(k==0){
					sum+=a[3];
				}else{
					sum-=a[3];
				}
				if(sum==7){
					op1=i;
					op2=j;
					op3=k;
					cout << a[0] << (op1 == 0 ? "+" : "-") << a[1] << (op2 == 0 ? "+" : "-") << a[2] << (op3 == 0 ? "+" : "-") << a[3] << "=7" << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}



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

int main() {
  string S; cin >> S;
  ll ans = 0;
  int cnt = 0;
  rep(i, 0, S.size()-1) {
    if(S[i] == 'A') cnt++;
    else {
      if(S[i] == 'B' && S[i+1] == 'C') {
        ans += cnt;
        i++;
      } else cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
var mod = 1e9+7;

console.log(main());
function main(){
  var n = o.a();
  var a = o.a();
  var b = o.a();
  var p = o.l();
  var dp = Array(n+1).fill(9e17);
  dp[0] = 0;
  for(var i = 0; i < n; i++){
    for(var x = 0; x <= n; x++){
      if(p[i] === x || dp[x] === 9e17)continue;
      if(x < p[i]){
        if(dp[x] < dp[p[i]])dp[p[i]] = dp[x];
        dp[x] += a;
      }else{
        dp[x] += b;
      }
    }
  }
  return Math.min(...dp);
}

Measured memory_bytes: 10316
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

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

  double ex = 0;
  for (int i = 0; i < k; i++) {
    ex += (double)(p[i] + 1) / 2;
  }

  double ans = ex;
  for (int i = k; i < n; i++) {
    ex += (double)(p[i] + 1) / 2;
    ex -= (double)(p[i-k] + 1) / 2;
    ans = max(ans, ex);
  }

  cout << setprecision(9) << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S;
	cin >> S;
	int N = S.size();
	string S0 = "0", S1 = "1";
	for(int i = 1; i < N; i++){
		S0 += (i%2 ? "1" : "0");
		S1 += (i%2 ? "0" : "1");
	}
	int sum0 = 0, sum1 = 0;
	for(int i = 0; i < N; i++){
		if(S[i] != S0[i])
			sum0++;
		if(S[i] != S1[i])
			sum1++;
	}

	cout << (sum0>sum1 ? sum1 : sum0) << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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


    rep(i, 0, s.size()){
        cout << 'x';
    }
    cout << endl;
}


Measured memory_bytes: 256
/***************************************************
	> File Name: Unkown_Error.cpp
	> Author: Zcorpio
	> Mail: 1113043195@qq.com 
	> Created Time: [Data_Deleted]
***************************************************/
#include<bits/stdc++.h>
//#define int long long
#define rint register int
#define mst(a,b) memset(a,b,sizeof(a))
#define go(u) for(int i=head[u],v=to[i];i;v=to[i=nxt[i]])
#define F(i,a,b) for(register int i=(a),i##_end=(b);i<=i##_end;++i)
#define R(i,a,b) for(register int i=(a),i##_end=(b);i>=i##_end;--i)
#define File(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
//const int mod=1e9+7;
//const int mod=998244353;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
/*
template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline bool chkmin(T &a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool chkmax(T &a,T b){return a>b?a=b,1:0;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b)
{while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
inline void write(T k,char ch=0)
{
	if(k<0)k=-k,putchar('-');
	if(k>=10)write(k/10);
	putchar(k%10+'0');
	if(ch)putchar(ch);
}
inline void add(int u,int v)
{
	cnt++;
	nxt[cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
}
*/
inline int read()
{
	int x=0;
	bool f=0;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') f=1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return f?-x:x;
}
int main()
{
	//File("");
	int n=read(),m=read();
	if(n<10&&m<10) cout<<n*m<<endl;
	else cout<<-1<<endl;
	return 0;
}


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

using namespace std;

typedef long long int ll;

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

  double h, w;
  cin >> h >> w;
  double ans = 1000000.00;
  for(double i = 1; i < h; i++){
    vector < double > v;
    v.push_back(i * w);
    v.push_back(ceil(((h - i) / 2.0)) * w);
    v.push_back(floor((h - i) / 2.0) * w);
    sort(v.begin(), v.end());
    ans = min(ans, v[2] - v[0]);
    v.clear();

    v.push_back(i * w);
    v.push_back(floor(w / 2.0) * (h - i));
    v.push_back(ceil(w / 2.0) * (h - i));
    sort(v.begin(), v.end());
    ans = min(ans, v[2] - v[0]);
    v.clear();
  }

  for(double i = 1; i < w; i++){
    vector < double > v;
    v.push_back(i * h);
    v.push_back(ceil(((w - i) / 2.0)) * h);
    v.push_back(floor((w - i) / 2.0) * h);
    sort(v.begin(), v.end());
    ans = min(ans, v[2] - v[0]);
    v.clear();

    v.push_back(i * h);
    v.push_back(floor(h / 2.0) * (w - i));
    v.push_back(ceil(h / 2.0) * (w - i));
    sort(v.begin(), v.end());
    ans = min(ans, v[2] - v[0]);
    v.clear();
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
D1 = [0]*N
D2 = [0]*N
for i in range(N):
    D1[i],D2[i] = map(int, input().split())
    
check = 0
for i in range(N):
    if D1[i]==D2[i]:
        check += 1
    else:
        check = 0
        
    if check == 3:
        break
        
if check >= 3:
    print("Yes")
else:
    print("No")

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

const double INF=1e9;

struct edge{
    int to;
    double cost;
    edge(int to,double cost):
        to(to),cost(cost){}
    edge(){}
};
int N,M,T,s,g;
double t[8];
vector<edge>G[30];

void solve(){
        double dp[30][1<<8];
        fill_n(*dp,30*(1<<8),INF);
        dp[s][0]=0;
        for(int j=0;j<(1<<T);j++){

            for(int i=0;i<N;i++){
                if(dp[i][j]==INF)continue;
                for(int k=0;k<(int)G[i].size();k++){
                    edge &e=G[i][k];
                    for(int l=0;l<T;l++){
                        if((j>>l)&1)continue;

                        dp[e.to][j|(1<<l)]=min(dp[e.to][j|(1<<l)],dp[i][j]+e.cost/t[l]);
                    }
                }

            }
        }
        double minCost=INF;

        for(int i=0;i<(1<<T);i++){
            minCost=min(minCost,dp[g][i]);
        }

        if(minCost==INF)puts("Impossible");
        else printf("%.3lf\n",minCost);

        return;
}

int main(){
        while(scanf("%d%d%d%d%d",&T,&N,&M,&s,&g),N||M||T||s||g){
            s--;g--;
            for(int i=0;i<N;i++)G[i].clear();
            for(int i=0;i<T;i++)scanf("%lf",&t[i]);
            for(int i=0;i<M;i++){
                    int a,b,c;
                    scanf("%d%d%d",&a,&b,&c);
                    a--;b--;
                    G[a].push_back(edge(b,c));
                    G[b].push_back(edge(a,c));
            }
            solve();

        }

        return 0;
}

Measured memory_bytes: 1320
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
import math
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    a, b, h, m = map(int, input().split())

    minute_angle = m * 2 * math.pi / 60
    hour_angle = h * 2 * math.pi / 12 + minute_angle / 12

    x = (math.cos(minute_angle) * a - math.cos(hour_angle) * b)
    y = (math.sin(minute_angle) * a - math.sin(hour_angle) * b)

    print((x ** 2 + y ** 2) ** 0.5)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 66112
import java.io.*;
import java.io.IOException;

class Main{
	public static void main(String args[]){
		int[] flagArray = new int[52];
		int haveCard = 0;
		int num=0;
		String[] pattern = {"S","H","C","D"};
		String[] inp = new String[2];
		String ans="";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			
			haveCard = Integer.parseInt(br.readLine());
			
			for(int i=0;i<haveCard;i++){
				inp = br.readLine().split("[\\s]+");
				
				switch(inp[0]){
					case "S":
						num = Integer.parseInt(inp[1]);
						break;
					case "H":
						num = Integer.parseInt(inp[1])+13;
						break;
					case "C":
						num = Integer.parseInt(inp[1])+13*2;
						break;
					case "D":
						num = Integer.parseInt(inp[1])+13*3;
						break;
					default:
						throw new IOException("None of \"S\",\"H\",\"C\",\"D\"");
				}
				flagArray[num-1]=1;
			}
			
		}catch(IOException e){
			System.out.println(e);
		}
		for(int i=0;i<flagArray.length;i++){
			if(flagArray[i]==0){
				switch(i/13){
					case 0:
						ans ="S "+String.valueOf(i+1);
						break;
					case 1:
						ans ="H "+String.valueOf(i%13+1);
						break;
					case 2:
						ans ="C "+String.valueOf(i%13+1);
						break;
					case 3:
						ans ="D "+String.valueOf(i%13+1);
						
				}
				System.out.println(ans);
			}
		}
		
	}
}


Measured memory_bytes: 24532
#include <stdio.h>

long long int gcd(long long int x,long long int y)
{
	if(x<y)return gcd(y,x);
	else if(y==0)return x;
	else return ((y>=(x-y)) ? gcd(y,(x-y)) : gcd((x-y),y));
}


int main()
{
	long long int a,b,c,d,g,lcm;
	long long int n,m,o=0;
	//nは[a,b]区間中のcで割り切れる整数の個数
	//mは[a,b]区間中のdで割り切れる整数の個数
	
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	a--;
	g=gcd(c,d);
	n=(b/c)-(a/c);
	m=(b/d)-(a/d);
	
	lcm=c*d/g;
	o=(b/lcm)-(a/lcm);
	
	//printf("%lld,%lld,%lld,%lld\n",lcm,n,m,o);
	printf("%lld",((b-a)-n-m+o));
	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int INF=1e18;
const int MOD=1e9+7;
const int MAX_N = 1e5;

int n;
struct Edge{
    int cost,to;
    Edge(int cost,int to):cost(cost),to(to){}
    bool operator<(const Edge& a) const{
        return cost >a.cost;
    }
};
using Graph=vector<Edge>;
Graph G[MAX_N];
bool used[MAX_N];
int res=0;

int prim(){
    REP(i,n)used[i]=false;
    used[0]=true;
    priority_queue<Edge>q;
    for(auto v:G[0]){
        q.push(v);
    }
    while(q.size()){
        Edge d=q.top();q.pop();
        if(used[d.to])continue;
        res+=d.cost;
      	used[d.to]=true;
        for(auto v:G[d.to]){
            if(!used[v.to])q.push(v);
        }
    }
    return res;
}
typedef pair<int,int> P;

signed main(){
    cin >> n;
    vector<P> x(n),y(n);
    REP(i,n){
        int a, b; cin >> a >> b;
        x[i] = {a,i};
        y[i] = {b,i};
    }
    sort(all(x));
    sort(all(y));
    REP(i,n-1){
        int cx = abs(x[i].first-x[i+1].first);
        int i1 = x[i].second;
        int i2 = x[i+1].second;
        int cy = abs(y[i].first-y[i+1].first);
        int i3 = y[i].second;
        int i4 = y[i+1].second;
        G[i1].pb({cx,i2});
        G[i2].pb({cx,i1});
        G[i3].pb({cy,i4});
        G[i4].pb({cy,i3});
    }
    cout << prim() << endl;
}

Measured memory_bytes: 16628
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
 
using namespace std;
 
typedef long long ll;
 
const ll INF = 1e9, MOD = 1e9 + 7, MOD2 = 1e6 + 3;

string s;

int dp[190][190][190][20], last[190][190], n, m;

char c[200][200];


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

	for (int i = 0; i < n; i++) {
		scanf ("%s", c[i]);

		for (int j = m - 1; j >= 0; j--)
		{
			if (j != m - 1 && c[i][j] == c[i][j + 1]) last[i][j] = last[i][j + 1];
			else last[i][j] = j;
		}
	}

	for (int i = 0; i < m; i++)
		for (int k = 0; k < n; k++)
			for (int j = 0; j + k < n; j++) {
				if (!k) dp[j][j][i][0] = last[j][i];
				else if (c[j][i] == c[j + 1][i]) {
					dp[j][j + k][i][0] = min (last[j][i], dp[j + 1][j + k][i][0]);
				}
				else dp[j][j + k][i][0] = -1;
			}

	for (int c = 1; c <= 16; c++) {
		for (int i = 0; i < m; i++) {
			for (int l = 0; l < n; l++)
				for (int r = l; r < n; r++) {
					if (dp[l][r][i][c-1] != m - 1) {
						dp[l][r][i][c] = dp[l][r][dp[l][r][i][c-1] + 1][c-1];
					}
					else dp[l][r][i][c] = m - 1;
				}

			for (int l = 0; l < n; l++) {
				int ptr = l;

				for (int r = l; r < n; r++) {
					for (; ptr < r - 1 && dp[l][ptr][i][c - 1] >= dp[ptr + 1][r][i][c - 1]; ptr++);

					if(l <= ptr - 1) dp[l][r][i][c] = max(dp[l][r][i][c] , min(dp[l][ptr - 1][i][c - 1] , dp[ptr][r][i][c - 1]));
					dp[l][r][i][c] = max(dp[l][r][i][c] , min(dp[l][ptr][i][c - 1] , dp[ptr + 1][r][i][c - 1]));
					if(ptr + 2 <= r) dp[l][r][i][c] = max(dp[l][r][i][c] , min(dp[l][ptr + 1][i][c - 1] , dp[ptr + 2][r][i][c - 1]));
				}
			}
		}
	}

	for (int c = 0; c <= 16; c++)
		if (dp[0][n - 1][0][c] == m - 1) {
			cout << c;
			return 0;
		}
}

Measured memory_bytes: 504064
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

using namespace std;

inline bool inRange(int a, int x, int b) {
    return a <= x && x < b;
}

void fill(vector<vector<int> > &v, int r, int c) {
    queue<pair<int,int> > q;
    q.push(make_pair(r, c));
    v[r][c] = 0;
    while(!q.empty()) {
        const pair<int,int> cur = q.front();
        q.pop();
        for(int dr = -1; dr <= 1; ++dr) {
            for(int dc = -1; dc <= 1; ++dc) {
                int nr = cur.first + dr;
                int nc = cur.second + dc;
                if(inRange(0, nr, v.size()) && 
                   inRange(0, nc, v[0].size()) &&
                   v[nr][nc])
                {
                    v[nr][nc] = 0;
                    q.push(make_pair(nr, nc));
                }
            }
        }
    }
}

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

    while(true) {
        int C, R;
        cin >> C >> R;
        if(!C && !R) break;

        vector<vector<int> > v(R, vector<int>(C));
        for(int i = 0; i < R; ++i) 
            for(int j = 0; j < C; ++j)
                cin >> v[i][j];

        int cnt = 0;
        for(int r = 0; r < R; ++r) {
            for(int c = 0; c < C; ++c) {
                if(v[r][c]) {
                    ++cnt;
                    fill(v, r, c);
                }
            }
        }

        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll ans = 0;
    rep(C, 1, N) {
        int rest = N - C;
        for (int A = 1; A * A <= rest; ++A) {
            if (rest % A) {
                continue;
            }
            ans += 2;
            if (A * A == rest) {
                --ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
a = int(input())
b = int(input())
c = int(input())
cond = int(input())

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            res = 500 * i + 100 * j + 50 * k
            if(res == cond):
                count = count + 1
print(count)

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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < K; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            A[a-1]++;
        }
    }
    int count = 0;
    for(int i = 0; i < N; i++){
        if(A[i] == 0){
            count++;
        }
    }
    cout << count <<endl;

    return 0;
}



Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    string before,after;
    int n;
    cin >> n;
    cin >> before;
    bool ans = true;
    map<string,int> a;
    a[before]++;
    //cout << a[before] << endl;
    //a.insert(make_pair(before,1));//要素の追加

    REP(i,n-1){
        cin >> after;
        
        if(before[before.length()-1] != after[0]){
            ans = false;
        }
        a[after]++;
        //a.insert(make_pair(after,1));//要素の追加
        before = after;
        //cout << before << ans << endl;
    }

    map<string,int>::iterator ite;
    for(ite = a.begin();ite != a.end();ite++){
        if(ite->second > 1){
            ans = false;
        }
    }

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

    return 0;
}

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


  
int main() {
  int N,K;
  cin >> N >> K;
  vector<long long> a(N-1);
  vector<long long> b(N-1);
  vector<long long> wi(N,0);
  
  for (int i=0; i<N-1; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > b[i]) {
      swap(a[i],b[i]);
    }
    a[i]--;
    b[i]--;
    wi[a[i]]++;
    wi[b[i]]++;
  }
  
  long long ans = K;
  
  
  for (int i=0; i<N; i++) {
    if (i==0) {
      for (int j=0; j<wi[i]; j++) {
        ans *= K-j-1;
        ans %= 1000000007;
      }
    }
    else {
      for (int j=0; j<wi[i]-1; j++) {
        ans *= K-j-2;
        ans %= 1000000007;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2560
n=int(input())
#li1=list(map(int,input().split())) #li=[int(x) for x in input.split()] 
li=[int(x) for x in input().split()]

#print(li1,li2)
for i in range(n):
    v = li[i]
    j = i-1
    while j >= 0 and li[j] > v:
        li[j+1] = li[j]
        j-=1
    li[j+1] = v
    l=[str(a) for a in li]
    l=" ".join(l)
    print(l)



Measured memory_bytes: 5604
s = gets.chop
k = gets.chop.to_i

ans = 1
one_len = 0
s.split('').each do |str|
    i = str.to_i
    if i == 1
        one_len += 1
        break if one_len == k
        next
    end
    ans = i
    break
end

p ans

Measured memory_bytes: 1788
//Catchharsh
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (int x,int n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    vector<ll> seve;
    void  seveprime()
    {
      int prime[1000000]={0};
      for(int i=2;i*i<1000000;i++)
       {
        if(prime[i]==0)
         {
      	  for(int j=i*2;j<=1000000;j+=i)
           prime[j]=1;
         }
       }
       for(int i=2;i<=1000000;i++)
       {
       	if(prime[i]==0)
       		seve.pb(i);
       }
    }
    bool compare(pair<pair<string,ll>,int> a,pair<pair<string,ll>,int> b)
    {
    	if(a.F.F!=b.F.F)
    		return a.F.F<b.F.F;
    		else
    			return a.F.S>b.F.S;
    }
    int main()
    {   
         IOS;
         ll n,i,j,k;
         cin>>n;
         vector<pair<pair<string,ll>,int> >v(n);
         for(i=0;i<n;i++)
         	{
         		cin>>v[i].F.F>>v[i].F.S;
         		v[i].S=i+1;
         	}
         	sort(v.begin(),v.end(),compare);
         	for(i=0;i<n;i++)
         		cout<<v[i].S<<endl;

    }

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int ans = 0;
		int n = sc.nextInt();
		int h[] = new int[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int cnt = 0; 
		for(int i = 1; i < n; i++) {
			if (h[i] <= h[i - 1]) {
				cnt++;
				ans = Math.max(ans, cnt);
			}
			else {
				cnt = 0;
			}
		}
		
		System.out.print(ans);
	}
}

Measured memory_bytes: 49524
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 1e5 + 20;
int n, L[N], R[N], mx, ans;
set <pair<pii, int>> st1, st2;

inline void add (int i)
{
	st1.insert({{L[i], R[i]}, i});
	st2.insert({{R[i], L[i]}, i});
}

inline void rmv (int i)
{
	st1.erase({{L[i], R[i]}, i});
	st2.erase({{R[i], L[i]}, i});
}

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

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> L[i] >> R[i];
		add(i);

		mx = max(mx, R[i] - L[i] + 1);
	}

	int p = (*st1.rbegin()).S;
	rmv(p);

	int curR = R[p];

	while (_sz(st1))
	{
		ans = max(ans, max(0, curR - L[p] + 1) + max(0, ((*st2.begin()).F.F) - ((*st1.rbegin()).F.F) + 1));

		int q = (*st2.rbegin()).S;

		rmv(q);
		curR = min(curR, R[q]);
	}

	ans = max(ans, max(0, curR - L[p] + 1) + mx);

	cout << ans << '\n';
}


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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  int n; cin >> n;
  vii a(2);
  a[0].resize(n);
  a[1].resize(n);
  rep(i,n) cin >> a[0][i];
  rep(i,n) cin >> a[1][i];

  int max_v = 0;
  int c;
  rep(i,n){
    c = 0;
    rep(j,i+1) c += a[0][j];
    FOR(j,i,n) c += a[1][j];
    //cout << c << endl;
    max_v = max(c,max_v);
  }
  cout << max_v << endl;
}


Measured memory_bytes: 256