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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> rows;
    vector<vector<int> > score_rows;
    vector<vector<int> > score_columns;
    vector<int> tmp;
    for (int j = 0; j < W; j++) {
        tmp.push_back(0);
    }
    for (int i = 0; i < H; i++) {
        string r;
        cin >> r;
        rows.push_back(r);
        score_rows.push_back(tmp);
        score_columns.push_back(tmp);
    }
    
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (rows[y][x] == '#') {
                score_rows[y][x] = 0;
            } else {
                int count = 1;
                for (int xx = x + 1; xx < W; xx++) {
                    if (rows[y][xx] == '#') {
                        break;
                    }
                    count++;
                }
                for (int xx = x; xx < x + count; xx++) {
                    score_rows[y][xx] = count;
                }
                x += count;
            }
        }
    }
    for (int x = 0; x < W; x++) {
        for (int y = 0; y < H; y++) {
            if (rows[y][x] == '#') {
                score_columns[y][x] = 0;
            } else {
                int count = 1;
                for (int yy = y + 1; yy < H; yy++) {
                    if (rows[yy][x] == '#') {
                        break;
                    }
                    count++;
                }
                for (int yy = y; yy < y + count; yy++) {
                    score_columns[yy][x] = count;
                }
                y += count;
            }
        }
    }

    int result = 0;
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (result < score_columns[y][x] + score_rows[y][x] - 1) {
                result = score_columns[y][x] + score_rows[y][x] - 1;
            }
        }
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 35712
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    ls = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    for i in range(1, 10):
        if n / i in ls:
            print("Yes")
            exit()
    print("No")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
a, b = gets.chomp.split.map(&:to_i)

x = (1..999).to_a

(1...999).each do |i|
  x[i] = x[i] + x[i - 1]
end

x.reverse_each do |i|
  if x.include?(b + i - a)
    puts i - a
    break
  end
end

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

int dp[100007][3];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        vector<int> work(3);
        cin >> work[0] >> work[1] >> work[2];
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) {
                    dp[i][j] = max(dp[i][j], dp[i-1][k] + work[j]);
                }
            }
        }
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]});
}


Measured memory_bytes: 1408
import sys
S = input()
T = input()
flag = 0
for i in range(len(S)): #i番目まで
    st1 = S[:i+1]
    st2 = S[i+1:]
    st3 = T[-i-1:]
    st4 = T[:-i-1]
    if st1 == st3 and st2 == st4:
        flag = 1
if flag == 0:
    print("No")
else:
    print("Yes")

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  int a,p;
  cin>>a>>p;

  cout<<(a*3+p)/2<<endl;

return 0;}


Measured memory_bytes: 256
def solve(mm, cmd):
	bf = cmd[0]
	c = 0
	ans = ""
	for s in cmd[1::]:
			if bf == s:
				c += 1
			else:
				if s == '0':
					ans += mm[bf][c%len(mm[bf])]
				c = 0
				bf = s
	return ans

def main():
	N = int(input())
	cc = [
		[".",",","!","?"," "],
		["a","b","c"],
		["d","e","f"],
		["g","h","i"],
		["j","k","l"],
		["m","n","o"],
		["p","q","r","s"],
		["t","u","v"],
		["w","x","y","z"]]
	mm = dict(zip(
		[str(i) for i in range(1,10)],
		cc
	))
	for _ in range(N):
		cmd = input()
		print(solve(mm,cmd))

if __name__ == '__main__':
	main()


Measured memory_bytes: 5624
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [0] * N
    X = [[]  for _ in range(N)]
    for i in range(N):
        A[i] = int(input())
        for _ in range(A[i]):
            x, y = map(int, input().split())
            x -= 1
            X[i].append((x,y))

    ans = 0
    for i in range(1<<N):
        T = []
        F = []
        for j in range(N):
            if (i>>j) & 1:
                T.append(j)
            else:
                F.append(j)
        flag = False
        for t in T:
            for x, y in X[t]:
                if y == 1:
                    if x in F:
                        flag = True
                        break
                else:
                    if x in T:
                        flag = True
                        break
            if flag:
                break
        if not flag:
            ans = max(ans, len(T))

    print(ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 45808
'use strict'
function main(input) {
  input = input.trim().split('\n')
  const NX = input[0].split(' ').map(v => v - 0)
  input = input[1].split(' ').map(v => Math.abs(v - NX[1]))

  const gcd = (x, y) => y === 0 ? x : gcd(y, x%y);
  for (let i = 1; i < NX[0]; i ++) {
    input[i] = gcd(input[i], input[i-1])
  }
  console.log(input[NX[0]-1])
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo 1e17
#define int long long

const int N = 1e5 + 5;
int n;
int a[N][5] , dp[N][5];

/// dp[i][j] là số điểm lớn nhất có dược qua i ngày và ngày thứ i làm công việc thứ j.

main()
{
    //freopen("C.inp","r",stdin);
    cin >> n;
    FOR(i , 1 , n)
        cin >> a[i][1] >> a[i][2] >> a[i][3];
    dp[1][1] = a[1][1];
    dp[1][2] = a[1][2];
    dp[1][3] = a[1][3];
    FOR(i , 2 , n)
        FOR(j , 1 , 3)
            FOR(k , 1 , 3)
                if(j != k)
                    dp[i][j] = max(dp[i][j] , dp[i - 1][k] + a[i][j]);
    cout << max(dp[n][1] , max(dp[n][2] , dp[n][3]));
}


Measured memory_bytes: 8064
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}


#pragma endregion


//ABC  091-B Two Colors Card Game

static char s[201][102];
int main(void) {
	int n,m,i;
	
	scanf("%d",&n);
	for (i = 0; i < n; i++) {
		scanf("%s", s[i]);
		s[i][100] = '1';
	}

	scanf("%d", &m);
	for (; i < m+n; i++) {
		scanf("%s", s[i]);
		s[i][100] = '2';
	}

	qsort(s, m+n, sizeof(s[0]), s_asort);

	int c=1, j = 0,rc;
	int max = 0;
	for (i = 1; i <= n+m; i++) {
		rc = strcmp(s[i], s[i - 1]);
		if (rc) {
			max = _max(max, c); c = 1; continue;
		}
		if (s[i][100] == '1')
			 c++;
		else if (s[i][100] == '2')
			 c--;
	}

	printf("\n%d\n", max);
	return 0;
}





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

int main(){
    int N;
    cin >> N;

    int s[N];
    int res = 0;
    bool tf = false;
    int not10 = 0;
    for(int i=0;i<N;i++){
        cin >> s[i];
    }
    sort(s, s+N);

    for(int i=0;i<N;i++){
        res += s[i];
        if(tf == false && s[i]%10 != 0){
            not10 = s[i];
            tf = true;
        }
    }

    if(res%10 == 0){
        if(tf == true){
            res = res - not10;
        }else{
            res = 0;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
/* ABC144-A
   Takatan */

#include<stdio.h>
int main(void){
    int number1, number2;

    scanf( "%d %d" , &number1, &number2);
    if(number1>=1 && number1 <=9 && number2>=1 && number2<=9){
        printf( "%d\n" , number1 * number2); /* 九九の範囲のとき */
    }else{
        printf( "-1\n" ); /* 九九の範囲外のとき */
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;



int main(void) {
    
    int a,b;
    cin>>a>>b;
    cout<<max(0,a-b*2)<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int d,int w){
	int ans=0;
	vvi vv(d,vi(w));
	//vvl sum(d+1,vl(w+1))
	rep(i,d)rep(j,w)cin>>vv[i][j];
	//rep(i,d)rep(j,w-1)sum[i][j+1]=sum[i][j]+vv[i][j];
	//rep(i,d-1)rep(j,w)sum[i+1][j]=sum[i][j]+vv[i][j];
	rep(i,d-2){
		rep(j,w-2){
			range(k,i+2,d){
				range(l,j+2,w){
					int sum=0;
					int mn=INF;
					int mx=0;
					range(a,i,k+1)range(b,j,l+1){
						if(a==i||a==k||b==j||b==l){
							chmin(mn,vv[a][b]);
						}
						else {
							chmax(mx,vv[a][b]);
							sum+=vv[a][b];
						}
					}
					if(mx<mn)chmax(ans,mn*(k-i-1)*(l-j-1)-sum);
				}
			}
		}
	}
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int d,w;
	while(cin>>d>>w,d)solve(d,w);
}


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

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

	rep(i,N)
		if(S.at(K-1) != S.at(i))
			S.at(i) = '*';
	cout << S << endl;	
}

Measured memory_bytes: 256
N, M, V, P = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
BORDER = A[P - 1]

# にぶたん: x番目の問題が採用される可能性があるか？
ok, ng = 0, N
while abs(ok - ng) > 1:
    x = (ok + ng) // 2
    x_score = A[x] + M
    remain_vote = M * (V - 1)

    if x_score < BORDER:
        ng = x
        continue

    for i, a in enumerate(A):
        if i == x:
            continue
        elif i < P and A[i] > BORDER:
            remain_vote -= M
        else:
            remain_vote -= min(M, x_score - a)

    if remain_vote <= 0:
        ok = x
    else:
        ng = x

print(ok + 1)


Measured memory_bytes: 20556
#!/usr/bin/env python3

D = int(input())
c = list(map(int, input().split()))

s = []
for d in range(D):
    s.append(list(map(int, input().split())))

def get_objective_function(output):
    objective_function = 0
    last = [[-1 for i in range(26)] for d in range(D)]

    for d in range(D):
        objective_function += s[d][output[d]]

        last[d][output[d]] = d
        if d < D-1:
            for i in range(26):
                last[d+1][i] = max(last[d][i], last[d+1][i])

        for i in range(26):
            objective_function -= c[i] * (d-last[d][i])

    point = max(10 ** 6 + objective_function, 0)
    return point

## outputの作成
# IOに基づくパターン
#output = []
#for _ in range(D):
#    output.append(int(input())-1)

# 最大効用での戦略
output = []
for d in range(D):
    output.append(s[d].index(max(s[d])))

## 目的関数の確認
#point = get_objective_function(output)
#print(point)

## 回答パターン
for d in range(D):
    print(output[d] + 1)


Measured memory_bytes: 9460
#include<stdio.h>
int isprime(int a);
int main(){
  int a,b,c=0,i;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b);
    c+=isprime(b);
  }
  printf("%d\n",c);
  return 0;
}

int isprime(int a){
  int i=3;
  if(a==2)return 1;
  if(a<2 ||a%2==0)return 0;
  while(i*i<=a){
    if(a%i==0)return 0;
    i+=2;
  }
  return 1;
}




Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll A, B, N;
	cin >> A >> B >> N;
	ll ans;
	if (B - 1 <= N) ans = A * (B - 1) / B;
	else ans = A * N / B;
	cout << ans << endl;
	return 0;
}


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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int INF = 1e9 + 7;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int sum = 3 * c;
  int magic[3][3] = {0};
  magic[0][0] = a;
  magic[0][1] = b;
  magic[1][1] = c;
  magic[0][2] = sum - magic[0][0] - magic[0][1];
  magic[2][1] = sum - magic[0][1] - magic[1][1];
  magic[2][2] = sum - magic[0][0] - magic[1][1];
  magic[1][2] = sum - magic[0][2] - magic[2][2];
  magic[1][0] = sum - magic[1][1] - magic[1][2];
  magic[2][0] = sum - magic[2][1] - magic[2][2];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cout << magic[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}


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

int W,N;
int dp[1001][1001]; // 宝の数×重さ
struct Obj {
	int price;
	int weight;
} obj[1001];

int main(void){
	int cnt = 1;
	while (cin >> W, W) {
		// input
		cin >> N;
		char buf;
		for (int i = 0; i < N; i++) {
			cin >> obj[i].price >> buf >> obj[i].weight;
		}
		
		// init
		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= W; j++) {
				dp[i][j] = 0;
			}
		}
		dp[0][obj[0].weight] = obj[0].price;

		// calc
		int wei;
		for (int i = 0; i < N - 1; i++) {
			for (int j = 0; j <= W; j++) {
				if (j != 0 && dp[i][j] == 0) {
					continue;
				}
				// 下
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				// 右下
				if (wei = j + obj[i + 1].weight, wei <= W) {
					dp[i + 1][wei] = max(dp[i + 1][wei], dp[i][j] + obj[i + 1].price);
				}
			}
		}
		
		struct Obj res = {0, 0};
		for (int i = 0; i <= W; i++) {
			for(int j = 0; j < N; j++) {
				if (res.price < dp[j][i]) {
					res.price = dp[j][i];
					res.weight = i;
				}
			}
		}

		// output
		printf("Case %d:\n%d\n%d\n", cnt++, res.price, res.weight);
	}

	return 0;
}

Measured memory_bytes: 5064
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
count = 0
for i in range(2 ** n):
    on_number = [0] * m
    for j in range(n):
        if i >> j & 1:
            for k in range(m):
                if (j + 1) in s[k][1:]:
                    on_number[k] += 1
    flag = 0
    for k in range(m):
        if on_number[k] % 2 == p[k]:
            flag += 1
        if flag == m:
            count += 1
print(count)

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

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  sort(a.rbegin(), a.rend());
  if(a.at(0) < accumulate(a.begin()+1, a.end(), 0)) cout << "Yes";
  else cout << "No";
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ll N;
    scanf("%lld", &N);
    ll ans = N * (N - 1) / 2;
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  string S;
  cin >> S;
  ll i;
  ll sum=1;
  int joined = 0;
  for(i=1;i<S.length();i++){
    //cout << i;
    sum++;
    if(S[i-1] == S[i] && joined != 1){
      if(i==S.length()-1){
        sum-=1;
      }else{
        i++;
        joined = 1;
      }
    }else{
      joined = 0;
    }
  }
  cout << sum;
}


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

typedef pair<int, int> ii;

struct Node {
    bool d;
    vector<ii> tos;
};

int n, m;
vector<Node> ns;

int prim() {
    for (int i = 0; i < n; i++) {
        ns[i].d = false;
    }
    priority_queue<ii, vector<ii>, greater<ii> > q;
    q.push(make_pair(0, 0));
    int ans = 0;
    while (!q.empty()) {
        ii p = q.top();
        q.pop();
        int i = p.second;
        if (ns[i].d) {
            continue;
        }
        ns[i].d = true;
        ans += p.first;
        for (vector<ii>::iterator it = ns[i].tos.begin(); it != ns[i].tos.end(); it++) {
            q.push(make_pair(it->second, it->first));
        }
    }
    return ans;
}

int main() {
    while (cin >> n >> m, n|m) {
        ns.clear();
        ns.resize(n);
        for (int i = 0; i < m; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            ns[a].tos.push_back(make_pair(b, c));
            ns[b].tos.push_back(make_pair(a, c));
        }
        cout << prim() << endl;
    }
}

Measured memory_bytes: 1212
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
		 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
	    public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();	
	        int K = sc.nextInt();
	        boolean[] m = new boolean[N];
	        for(int i=0;i<K;i++) {
	        	int d = sc.nextInt();
	        	for(int j=0;j<d;j++) {
	        		m[sc.nextInt()-1]=true;
	        	}
	        }
	        
	        long ans=0;
	        for(int i=0;i<N;i++) {
	        	if(m[i]==false)ans++;
	        }
	        System.out.println(ans);
	        
	    }
	}


Measured memory_bytes: 46392
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

# grobalにmdを設定すること
class mint:
    def __init__(self, x):
        self.__x = x % md

    def __str__(self):
        return str(self.__x)

    def __neg__(self):
        return mint(-self.__x)

    def __add__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x + other)

    def __sub__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x - other)

    def __rsub__(self, other):
        return mint(other - self.__x)

    def __mul__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * other)

    __radd__ = __add__
    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * pow(other, md - 2, md))

    def __rtruediv__(self, other):
        return mint(other * pow(self.__x, md - 2, md))

    def __pow__(self, power, modulo=None):
        return mint(pow(self.__x, power, md))

md = 10**9+7

def main():
    n,k=MI()
    dp=[mint(0) for _ in range(k+1)]
    for a in range(k,0,-1):
        dp[a]+=pow(k//a,n,md)
        for b in range(2*a,k+1,a):
            dp[a]-=dp[b]
    ans=0
    for a in range(1,k+1):
        ans+=dp[a]*a
    print(ans)

main()

Measured memory_bytes: 27240
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

class UnionFindTree {
   public:
    vector<int> parent;
    vector<int> siz;

    UnionFindTree(int n) {
        siz.resize(n, 1);
        parent.resize(n);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

    int root(int x) {
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

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

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

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

int main() {
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<pair<int, int>> XY(N);
    REP(i, 0, N) cin >> XY[i].first >> XY[i].second;

    vector<int> indices(N, 0);
    iota(ALL(indices), 0);
    sort(ALL(indices), [&](auto l, auto r) { return XY[l] < XY[r]; });

    UnionFindTree uft(N + 1);
    set<pair<int, int>> s;
    for (auto i : indices) {
        // cout << "# i : " << i << endl;
        auto itr = s.lower_bound({XY[i].second, XY[i].first});
        if (itr != s.begin()) {
            itr--;
            while (true) {
                // cout << "--> unite : " << (*itr).second << " " << (*itr).first << endl;
                uft.unite((*itr).second, XY[i].first);
                if (itr == s.begin()) break;
                auto tmp = itr;
                itr--;
                s.erase(tmp);
            }
            // if ((*itr).first > XY[i].second) {
            //     s.erase(itr);
            //     s.insert({XY[i].second, XY[i].first});
            // }
        } else {
            s.insert({XY[i].second, XY[i].first});
        }
    }

    REP(i, 0, N) {
        cout << uft.size(XY[i].first) << endl;
    }

    return 0;
}

Measured memory_bytes: 11580
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

ll A, B, K;
int main(){
    scanf("%lld %lld %lld", &A, &B, &K);
    ll tA = A;
    A-= min(A, K);
    K-= min(tA, K);
    ll tB = B;
    B-=min(B, K);
    K-=min(tB, K);
    printf("%lld %lld\n", A, B);
    return 0;
}

Measured memory_bytes: 256
def resolve():
    n, a, b = input().strip().split(' ')
    n, a, b = [int(n), int(a), int(b)]
    s = input().strip()
    a_passed = 0
    b_passed = 0
    for i in range(len(s)):
        if s[i] == 'a':
            if a_passed + b_passed < a + b:
                a_passed = a_passed + 1
                print('Yes')
            else:
                print('No')
        elif s[i] == 'b':
            if a_passed + b_passed < a + b and b_passed < b:
                b_passed = b_passed + 1
                print('Yes')
            else:
                print('No')
        else:
            print('No')
resolve()


Measured memory_bytes: 51160
#include <stdio.h>
int main(){
	int n,a[3],i,j,k,x;
	scanf("%d\n",&n);
	for(i=1;i<=n;i++){
		scanf("%d %d %d",&a[0],&a[1],&a[2]);
		for(j=1;j<=3;j++){
			for(k=0;k<=1;k++){
				if(a[k]<a[k+1]){
					x=a[k];
					a[k]=a[k+1];
					a[k+1]=x;
				}
			}
		}
		if(a[2]*a[2]+a[1]*a[1]==a[0]*a[0]){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
const int MAXN=1e5+5;
const int MOD=1e9+7;
using namespace std;

int main(){
	string s;
	int a=0, b=0;
	cin>>s;
	for(int i=0;i<s.length();++i){
		if(s[i]=='0')
			a++;
		else
			b++;
	}
	printf("%d", 2*min(a, b));
	return 0;
}


Measured memory_bytes: 512
#include <iostream>

int n;
int main(){
  std::cin>>n;
  long long res=0;
  for(int i=0;i<n;++i){
    long long in;
    std::cin>>in;
    
    if(in%2==1)
      ++res;
  }
  
  if(res%2==0)
    std::cout<<"YES"<<std::endl;
  else
    std::cout<<"NO"<<std::endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
S += 'R'

ans = [0]*(len(S))
rcnt = 0
lcnt = 0
l = 0
pre = 'R'
for i, s in enumerate(S):
  if s == 'R':
    rcnt += 1
    if pre == 'L':
      ans[l-1] += lcnt//2
      ans[l] += (lcnt+1)//2
      lcnt = 0
  else:
    lcnt += 1
    if pre == 'R':
      l = i
      ans[i-1] = (rcnt+1)//2
      ans[i] += rcnt//2
      rcnt = 0
  pre = s
print(*ans[:-1])

Measured memory_bytes: 11308
k=int(input())
a=list(map(int,input().split()))
s=2+k*max(a)
l,r=s+1,0
while l-r>1:
    t=(l+r)//2
    p=t
    for i in a:
        t-=t%i
    if t>=2:
        l=p
    else:
        r=p
e=l
l,r=s+1,0
while l-r>1:
    t=(l+r)//2
    p=t
    for i in a:
        t-=t%i
    if t>2:
        l=p
    else:
        r=p
print(str(max(e,2))+" "+str(r)if r>e or r<2 else -1)

Measured memory_bytes: 14428
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;

	int n, w;
	int[] a, b;

	void run(){
		n=sc.nextInt();
		w=sc.nextInt();
		a=new int[n];
		b=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
		}
		for(int i=0; i<n; i++){
			b[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		// x累積和(mod 2)
		// x[i]=x[i-1] <=> S[i]=0
		// => -a[i]
		// x[i-w-1] = x[i+w] <=> S[i-w, i+w] = 0
		// => -b[i]

		// y[i] = x[i]+i mod 2
		// y[i] != y[i-1] => -a[i]
		// y[i-w-1] != y[i+w] => -b[i]

		int scoreSum=0, bestScore=-1;
		for(int i : a){
			scoreSum+=i;
		}
		for(int i : b){
			scoreSum+=i;
		}
		String ans=null;
		for(int sum=0; sum<2; sum++){
			V[] vs=new V[n+w*2+3];
			for(int i=0; i<vs.length; i++){
				vs[i]=new V();
			}
			V s=vs[n+w*2+1], t=vs[n+w*2+2];
			// [0, w]
			for(int i=0; i<=w; i++){
				if(i%2==0){
					s.add(vs[i], INF);
				}else{
					vs[i].add(t, INF);
				}
			}
			// [n+w, n+w*2]
			for(int i=n+w; i<=n+w*2; i++){
				if((i+sum)%2==0){
					s.add(vs[i], INF);
				}else{
					vs[i].add(t, INF);
				}
			}
			// [w+1, n+w]
			for(int i=w+1; i<=n+w; i++){
				int at=i-w-1;
				vs[i-w-1].add(vs[i+w], b[at]);
				vs[i+w].add(vs[i-w-1], b[at]);
				vs[i].add(vs[i-1], a[at]);
				vs[i-1].add(vs[i], a[at]);
			}
			int score=scoreSum-fordFulkerson(vs, s, t);
//			debug(score);
			if(score>bestScore){
				bestScore=score;
				for(V v : vs){
					v.used=false;
				}
				visit(s);
				StringBuilder sb=new StringBuilder();
				for(int i=w+1; i<=n+w; i++){
					if(vs[i-1].used^vs[i].used){
						sb.append(0);
					}else{
						sb.append(1);
					}
				}
				ans=sb.toString();
			}
		}
		println(ans);
	}

	void println(String s){
		System.out.println(s);
	}

	void visit(V v){
		v.used=true;
		for(E e : v.es){
			if(e.cap>0&&!e.to.used){
				visit(e.to);
			}
		}
	}

	int fordFulkerson(V[] vs, V s, V t){
		for(int flow=0;;){
			for(V v : vs)
				v.used=false;
			int f=dfs(s, t, INF);
			if(f==0)
				return flow;
			flow+=f;
		}
	}

	int dfs(V v, V t, int f){
		if(v==t)
			return f;
		v.used=true;
		for(E e : v.es){
			if(!e.to.used&&e.cap>0){
				int d=dfs(e.to, t, min(f, e.cap));
				if(d>0){
					e.cap-=d;
					e.rev.cap+=d;
					return d;
				}
			}
		}
		return 0;
	}

	class V{
		ArrayList<E> es=new ArrayList<E>();
		boolean used;

		void add(V to, int cap){
			E e=new E(to, cap), rev=new E(this, 0);
			e.rev=rev;
			rev.rev=e;
			es.add(e);
			to.es.add(rev);
		}
	}

	class E{
		V to;
		E rev;
		int cap;

		E(V to, int cap){
			this.to=to;
			this.cap=cap;
		}
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		new Main().run();
	}

}

Measured memory_bytes: 56124
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>

#define int unsigned long long

const int N = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(NULL);
        std::cout.tie(NULL);
    }
    
    int n;
    std::cin >> n;
    int p = 1;
    std::vector<int> a(n);
    for (int i = 0; i != n; ++i) {
        std::cin >> a[i];
        if (a[i] == 0) {
            std::cout << 0;
            return 0;
        }
    }
    for (int i = 0; i != n; ++i) {
        if (p > N / a[i]) {
            std::cout << -1;
            return 0;
        }
        p *= a[i];
    }
    std::cout << p;
    return 0;
}

Measured memory_bytes: 3988
#include "bits/stdc++.h"
using namespace std;
#define elif else if
typedef long long ll;
#define REP(i,a,n) for( ll i=n;i>=a;i--)
#define rep(i,a,n) for( ll i=a;i<n;i++)
const ll INF = 1e+9;
const ll MOD = 1000000007;
int main(){
    string plz;cin>>plz;
    int n;cin>>n;
    int ans=0;
    string ring[n];
    rep(i,0,n){
        cin>>ring[i];
    }
    rep(i,0,n){
        rep(j,0,10){
            if(ring[i][j]==plz[0]){
                int check=j,k=0;
                while(1){
                    check++;
                    k++;
                    if(check>=10){
                        check=0;
                    }
                     if(k>plz.size()-1)break;
                    if(ring[i][check]!=plz[k])break;
                   
                }
                if(k>=plz.size()-1){
                    ans++;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    string S,T;
    int A,B;
    string U;

    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if ( U== S) A--;
    else B--;

    cout << A << " " << B << endl;


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int x,t,i,j,a=1;

	scanf("%d",&x);

	for(i=2;i<=sqrt(x);i++){
		t=0;
		for(j=2;(t=pow(i,j))<=x;j++)
			if(a<t)
				a=t;
	}
	printf("%d",a);
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/ruby
# coding: utf-8

PI = Math.acos(-1)

n = gets.to_i
c = Array.new 21, 0
d = Array.new 21, 0

xs = gets.chomp.split(' ').map {|x| x.to_i}

c[xs[0]] = 1

(n-2).times do |i|
  x = xs[i+1]
  (21).times do |k|
    d[k + x] += c[k] if k+x < 21
    d[k - x] += c[k] if k-x > -1
  end
  (21).times do |k|
    c[k] = d[k]
    d[k] = 0
  end
end

puts c[xs[n-1]]

Measured memory_bytes: 6136
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;
const ll INF=1e14;
const int maxn=100000+5;

int N,Q;

#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)

#define val first
#define pos second
typedef pair<ll,int> Min;//Min(val,pos)

Min mn[maxn<<2];
ll add[maxn<<2];

void put_up(int x) {
	mn[x]=min(mn[lc],mn[rc]);
}

void put_down(int x) {
	if(!add[x]) return ;
	add[lc]+=add[x];
	mn[lc].val+=add[x];
	add[rc]+=add[x];
	mn[rc].val+=add[x];
	add[x]=0;
}

void build(int x,int l,int r) {
	mn[x]=Min(0,l);
	if(l==r) return ;
	build(lc,l,mid);
	build(rc,mid+1,r);
	put_up(x);
}

void update(int x,int l,int r,int ql,int qr,ll v) {
	if(ql<=l&&r<=qr) {
		add[x]+=v;
		mn[x].val+=v;
		return ;
	}
	put_down(x);
	if(ql<=mid) update(lc,l,mid,ql,qr,v);
	if(qr>mid) update(rc,mid+1,r,ql,qr,v);
	put_up(x);
}

Min query(int x,int l,int r,int ql,int qr) {
	if(ql<=l&&r<=qr) return mn[x];
	put_down(x);
	Min L(INF,N+1),R(INF,N+1);
	if(ql<=mid) L=query(lc,l,mid,ql,qr);
	if(qr>mid) R=query(rc,mid+1,r,ql,qr);
	return min(L,R);
}

int main() {
	int a;ll b;
	scanf("%d%d",&N,&Q);
	build(1,1,N);
	while(Q--) {
		scanf("%d%lld",&a,&b);
		while(b) {
			Min x=query(1,1,N,1,a);
			if(x.pos==1) {
				ll c=b/a;
				update(1,1,N,1,a,c);
				if((b-=c*a)>0) update(1,1,N,1,b,1);
				break;
			} else {
				ll v=query(1,1,N,x.pos-1,x.pos-1).val;
				if((v-x.val)*(a-x.pos+1)>b) {
					ll c=b/(a-x.pos+1);
					update(1,1,N,x.pos,a,c);
					if((b-=c*(a-x.pos+1))>0) update(1,1,N,x.pos,x.pos+b-1,1);
					break;
				} else {
					b-=(v-x.val)*(a-x.pos+1);
					update(1,1,N,x.pos,a,v-x.val);
				}
			}
		}
	}
	for(int i=1;i<=N;i++) printf("%lld\n",query(1,1,N,i,i).val);
	return 0;
}

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

string s;

int main()
{
	int w;
	cin>>s>>w;
	for(int i=0;i<(int)s.length();i+=w)
		cout<<s[i];
	cout<<endl;
	
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(depth, l):
        if depth == 0:
            calc(l)
            return
        for i in range(4):
            dfs( depth - 1, l + str(i) )

    def calc(l):
        res = 0
        if not '0' in l or not '1' in l or not '2' in l:
            return
        aa = [[] for i in range(3)]
        for i,x in enumerate(list(l)):
            x = int(x)
            if x == 3:
                continue
            take = NLIST[i]
            aa[x].append(take)
        for i, a in enumerate(aa):
            if len(a) > 1:
                res += 10 * (len(a) - 1)
            res += abs(ABC[i] - sum(a))
        RESULT.append(res)




    RESULT = []
    N,A,B,C = map(int, lines.pop(0).split(' '))
    ABC = [A,B,C]
    NLIST = []
    for i in range(N):
        NLIST.append(int(lines.pop(0)))
    dfs(N, "")
    print(min(RESULT))
    
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 5008
n,m = map(int,input().split())
G = [[] for i in range(n)]
deg = [0 for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    G[b].append(a)
    deg[a] += 1

from collections import deque
q = deque()
add,pop=q.append,q.popleft
for i in range(n):
    if deg[i]==0:
        add(i)

order = []
while q:
    v = pop()
    order.append(v)
    for nv in G[v]:
        deg[nv] -= 1
        if deg[nv] == 0:
            add(nv)

for i in order[::-1]:
    print(i)


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

int main() {
	// your code goes here
	string s;
	cin >> s;
	if ((s[1]==s[0]&&s[1]!=s[2])||(s[1]!=s[0]&&s[1]==s[2])||(s[1]!=s[0]&&s[1]!=s[2])) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))

pos = A[bisect_left(A, 0):]
pos.reverse()
neg = A[:bisect_left(A, 0)]

mod = 10**9+7
ans = 1
if len(pos) == 0 and K % 2 == 1:
    for i in range(K):
        ans *= neg[-i-1]
        ans %= mod
elif N == K:
    for i in range(K):
        ans *= A[i]
        ans %= mod
else:
    p, n = 0, 0
    for i in range(0, K-1, 2):
        v1 = 0
        v2 = 0
        if K % 2 == 0:
            if len(pos) >= p + 2:
                v1 = pos[p] * pos[p+1]
        else:
            if len(pos) >= p + 3:
                v1 = pos[p] * pos[p+1]

        if len(neg) >= n + 2:
            v2 = neg[n] * neg[n+1]

        if v2 > v1:
            ans *= v2
            ans %= mod
            n += 2
        else:
            ans *= v1
            ans %= mod
            p += 2

    if K % 2 == 1:
        ans *= pos[p]
        ans %= mod

print(ans)

Measured memory_bytes: 95768
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MAX = 55;
const Int D = 22;
Int c[MAX][MAX];
Int r[MAX*MAX];
Int x[MAX],y[MAX];
Int w,h,n;
Int used[MAX];
Int ok;
bool check(Int a){
  Int u[MAX][MAX];
  memset(u,0,sizeof(u));
  
  Int dy[]={0,0,1,-1};
  Int dx[]={1,-1,0,0};
  
  using P = pair<Int, Int>;
  queue<P> q;
  u[y[a]][x[a]]=1;
  q.emplace(y[a],x[a]);

  Int cnt=0;
  while(!q.empty()){
    Int cy,cx;
    tie(cy,cx)=q.front();q.pop();
    cnt++;
    for(Int k=0;k<4;k++){
      Int ny=cy+dy[k],nx=cx+dx[k];
      if(u[ny][nx]) continue;
      if(!c[ny][nx]) continue;
      Int b=r[ny*MAX+nx];
      assert(~b);
      if(used[a]!=used[b]) continue;
      u[ny][nx]=1;
      q.emplace(ny,nx);
    }
  }
  return (cnt*2==n);
};

void print(int k){
  //return;
  if(k&1){
    for(int i=D;i+D<MAX;i++){
      for(int j=D;j+D<MAX;j++){
	cout<<c[i][j]<<" ";
      }
      cout<<endl;
    }
  }
  if(k&2){
    for(int i=D;i+D<MAX;i++){
      for(int j=D;j+D<MAX;j++){
	if(!c[i][j]) cout<<c[i][j]<<" ";
	else cout<<used[r[i*MAX+j]]<<" ";
      }
      cout<<endl;
    }
  }
}

void dfs(Int a,Int b,Int k,Int d,Int p){
  if(p==n){
    ok|=check(a)&&check(b);
    if(ok) print(0);
    return;
  }
  if(ok) return;
  if(used[p]){
    dfs(a,b,k,d,p+1);
    return;
  }
  // used[p]=1
  [&]{
    Int dy=y[a]-y[p];
    Int dx=x[a]-x[p];
    if(k) dx*=-1;
    for(Int i=0;i<d;i++){
      Int ny=-dx,nx=dy;
      dy=ny;dx=nx;
    }
    Int qy=y[b]-dy;
    Int qx=x[b]-dx;
    if(!c[qy][qx]) return;
    Int q=r[qy*MAX+qx];
    assert(~q);
    if(used[q]) return;
    if(p==q) return;
    
    used[p]=1;
    used[q]=2;
    
    dfs(a,b,k,d,p+1);

    used[p]=0;
    used[q]=0;
  }();
  if(ok) return;
  // used[p]=2
  [&]{
    Int dy=y[b]-y[p];
    Int dx=x[b]-x[p];
    for(Int i=0;i<4-d;i++){
      Int ny=-dx,nx=dy;
      dy=ny;dx=nx;
    }
    if(k) dx*=-1;
    Int qy=y[a]-dy;
    Int qx=x[a]-dx;
    {
      if(k) dx*=-1;
      for(Int i=0;i<d;i++){
	Int ny=-dx,nx=dy;
	dy=ny;dx=nx;
      }
      assert(y[b]-y[p]==dy);
      assert(x[b]-x[p]==dx);
    }
    if(!c[qy][qx]) return;
    Int q=r[qy*MAX+qx];
    assert(~q);
    if(used[q]) return;
    if(p==q) return;
    
    used[p]=2;
    used[q]=1;
    
    dfs(a,b,k,d,p+1);

    used[p]=0;
    used[q]=0;
  }();
};
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  while(cin>>w>>h,w){
    memset(c,0,sizeof(c));
    for(Int i=0;i<h;i++)
      for(Int j=0;j<w;j++)
	cin>>c[i+D][j+D];
    
    memset(r,-1,sizeof(r));
    memset(y,-1,sizeof(y));
    memset(x,-1,sizeof(x));
    n=0;
    for(Int i=0;i<MAX;i++){
      for(Int j=0;j<MAX;j++){
	if(!c[i][j]) continue;
	y[n]=i;
	x[n]=j;
	r[i*MAX+j]=n++;
      }
    }
    if(n&1){
      cout<<"NO"<<endl;
      continue;
    }
    ok=0;
    for(Int i=0;i<n;i++){
      for(Int j=0;j<i;j++){
	for(Int k=0;k<2;k++){
	  for(Int d=0;d<4;d++){
	    memset(used,0,sizeof(used));
	    used[i]=1;
	    used[j]=2;
	    dfs(i,j,k,d,0);
	    if(ok) goto END;
	  }
	}
      }
    }
  END:
    cout<<(ok?"YES":"NO")<<endl;
  }
  return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,Q;
vector<vector<int>> G;
vector<int> dp;
void input(){
    fast_io();
    cin >> N >> Q;
    G.resize(N);
    dp.assign(N,0);
    for (int i = 0; i < N-1; i++)
    {
        int a,b; cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < Q; i++)
    {
        int p,x; cin >> p >> x;
        p--;
        dp[p]+=x;
    }
}

void dfs(int u=0, int p=-1){
    for(int v:G[u]){
        if(v==p) continue;
        dp[v] += dp[u];
        dfs(v,u);
    }
}


int solve(){
    dfs();
    for (int i = 0; i < N; i++)
    {
        cout << dp[i] << " ";
    }
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 23552
#include <stdio.h>

int fact(int n);

int main(void){
  int n,count;

  while(1){
    scanf("%d", &n);
    if(n==0){ break; }

    count=0;
    while(n>=5){
        count+=n/5;
        n/=5;
    }
    printf("%d\n",count);
  }

  return 0;
}



Measured memory_bytes: 2040
use std::io::stdin;

/**
 *   D
 */
fn main() {
    let n: i64 = {
         let mut s = String::new();
        stdin().read_line(&mut s).unwrap();
        let n = s.trim_right().parse().unwrap();
        n
    };

    let a :Vec<i64> = {
        let mut a: Vec<i64> = vec![];
        for i in 0..n {
            let mut s = String::new();
            stdin().read_line(&mut s).unwrap();
            let _a: i64 = s.trim_right().parse().unwrap();
            a.push(_a);
        }
        a
    };

    let mut isFirst = false;
    for n in a {
        if n % 2 == 1 {
            isFirst = true;
        }
    }
    if isFirst {
        println!("{}", "first")
    } else {
        println!("{}", "second")
    }
}


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

const int mod = 1000000007;

int main()
{
    int N;
    string S, T;
    cin >> N >> S >> T;

    vector<bool> f;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == T[i]) {
            f.push_back(true);
        }
        else {
            f.push_back(false);
            i++;
        }
    }

    int ans = f[0] ? 3 : 6;
    for (int i = 1; i < f.size(); i++) {
        if (!f[i - 1] && f[i]);
        else if (!f[i - 1] && !f[i]) ans = 3LL * ans % mod;
        else ans = 2LL * ans % mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256