akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  double d,s,t;  cin>>d>>s>>t;
  if(d/s <= t){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3720
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[10],b[10];
int lower(int f,int x,char z[])
{
	int num=0;
	int t=1;
	int i=f;
	while(i<=x-1)
	{
		if(i>f)num*=10;
		num+=int(z[i]-48);
		i++;
	}
	if(f) t=-1;
	return num*t;
}
int main()
{
	//printf("%d",'0');
	int a1,b1;
	scanf("%s",a);
	scanf("%s",b);
	//printf("%d %d\n",strlen(a),strlen(b));
	if(a[0]=='-') a1=lower(1,strlen(a),a);
	else a1=lower(0,strlen(a),a);
	if(b[0]=='-') b1=lower(1,strlen(b),b);
	else b1=lower(0,strlen(b),b);
	//printf("%d %d",a1,b1);
	printf("%d",max(a1+b1,max(a1-b1,a1*b1)));
}


Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
using namespace std;
const int N=22e4;

int a[N],r[N];
bool cmp(int x,int y){
	return a[x]<a[y];
}
int main(){
	ios::sync_with_stdio(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		r[i]=i;
	}
	sort(r,r+n,cmp);
	for(int i=0;i<n;i++)
		cout<<r[i]+1<<' ';
	return 0;
}

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

int main() {
  int n,m,x,min = 0;
  cin >> n >> m;
  int max = n;
  for(int i = 0; i < m; i++){
    cin >> x;
    if(x > min)
      min = x;
    cin >> x;
    if(x < max)
      max = x;
  }
  if(min > max)
    cout << 0 << endl;
  else
    cout << max - min + 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * 不安なら ll を使う.
 * 小数は double を忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
 * 比較するときは型まで注意
 * 区間の計算は累積和
 * 整数同士の割り算は整数に丸められるのでdoubleでキャストする
*/

/* ===== コーナーケースに気をつけろ ===== */

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

int main()
{
    int K;
    cin >> K;
    ll sum = 0;
    for(int i = 1; i <= K; i++) {
        for(int j = 1; j <= K; j++) {
            for(int k = 1; k <= K; k++) {
                ll tmp = gcd(i, j);
                sum += gcd(tmp, k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3604
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def warshallFloyd():
    for k in range(N):
        for i in range(N-1):
            for j in range(i, N):
                tmp = min(E[i][j], E[i][k] + E[k][j])
                E[i][j] = E[j][i] = tmp

def dfs(c, p, d):
    if c == R:
        ans[0] = min(ans[0], d)
        return
    for i in range(R):
        if used[i]:
            continue
        used[i] = True
        if p == -1:
            dfs(c+1, i, 0)
        else:
            dfs(c+1, i, d + E[S[p]-1][S[i]-1])
        used[i] = False

N, M, R = map(int, input().split())
S = list(map(int, input().split()))
E = [[float('inf')] * N for _ in range(N)]
for i in range(N):
    E[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    E[a][b] = E[b][a] = c
warshallFloyd()
ans = [float('inf')]
used = [False] * R
dfs(0, -1, 0)
print(*ans)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 3e5 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r; 
}
void solve()
{
	int n, k;
	cin >> n >> k;
	ll p[n + 1], c[n + 1];
	for(int i = 1; i <= n; ++i){
		cin >> p[i];
	}
	for(int i = 1; i <= n; ++i){
		cin >> c[i];
	}
	ll res = -1e18;
	for(int i = 1; i <= n; ++i){
		vector<int> u(n + 1);
		u[i] = 1;
		vector<int> els = {i};
		int j = p[i];
		int cnt = 2;
		while(!u[j]) {
			els.pb(j);
			u[j] = cnt;
			++cnt; 
			j = p[j];
		}
		if(k <= sz(els)) {
			ll cursum = 0;
			rep(x, k) {
				cursum += c[els[x]];
				res = max(res, cursum); 
			}
		}
		else{

			int ck = k;
			ck -= u[j] - 1;
			ll cursum = 0;
			for(int x = 0; x < u[j] - 1; ++x) {
				cursum += c[els[x]];
				res = max(res, cursum);
			}
			ll nxtsum = 0;
			for(int x = u[j] - 1; x < sz(els); ++x) {
				nxtsum += c[els[x]];
				res = max(res, cursum + nxtsum);
			}
			// cout << sz(els) << '\n';
			ll need = ck / (sz(els) - u[j] + 1);
			// cout << ck << " " << sz(els) << " " << u[j] - 1 << '\n';
			// continue;
			ll sumneed = 1ll * need * nxtsum;
			res = max(res, sumneed + cursum);
			ck %= (sz(els) - u[j] + 1);
			for(int x = u[j] - 1; x < u[j] - 1 + ck; ++x){
				sumneed += c[els[x]];
				res = max(res, sumneed + cursum);
			}
			ll another = 0;
			for(int x = u[j] - 1; x < sz(els); ++x){
				another += c[els[x]];
				res = max(res, (need - 1) * nxtsum + another);
			}
		}
	}
	cout << res;
}
 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 3804
A, B, C, D = [int(x) for x in input().split()]

Taka_HP = A
ao_HP = C

while True:
    ao_HP = ao_HP - B
    if(ao_HP <= 0):
        print("Yes")
        break
    Taka_HP = Taka_HP - D
    if(Taka_HP <= 0):
        print("No")
        break

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

int main()
{
    double r; 
    cin >> r;
    
    cout << fixed << setprecision(5);
    cout << M_PI * r * r << ' ' << 2.0 * M_PI * r << endl;
    
    return 0;
}


Measured memory_bytes: 3232
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int x = sc.nextInt();
      	int y = x / 100;
        int d = x % 100;//余り

      	for(int i = 1;i <= y; i++){//商の回数文ループ
          if(d >= 5){
            d -= 5;
          }else if(d >= 4){
            d -= 4;
          }else if(d >= 3){
            d -= 3;
          }else if(d >= 2){
            d -= 2;
          }else if(d >= 1){
            d -= 1;
          }
        }
    	if(d == 0){
           System.out.println(1);  
        }else{
           System.out.println(0);  
        }
    }
}

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

int main(){
    long long n,a,b,c,d,e,m,ans=5;
    cin>>n>>a>>b>>c>>d>>e;
    m=min(a,b);
    m=min(m,c);
    m=min(m,d);
    m=min(m,e);

    ans+=(n-1)/m;

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

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c=list(map(int,input().split()))
ans = 0
for i in range(n - 1):
	ans += b[a[i]-1]
	if a[i] + 1 == a[i + 1]:
		ans += c[a[i]-1]
ans += b[a[-1]-1] 
print(ans)


Measured memory_bytes: 3060
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto ss = readln.split.to!(long[]);

    long r;
    foreach (x; 1..N-1) {
        long rr;
        int i, j = N-1;
        while (i < N-1 && j > 0) {
            if (i == j || i == j+x || i > N-1-x || j < x) break;
            rr += ss[i] + ss[j];
            r = max(r, rr);
            i += x;
            j -= x;
        }
    }
    writeln(r);
}

Measured memory_bytes: 4476
#include <iostream>
#include <vector>

namespace ABC172
{
  static const int N_MAX = 200001;

  class C
  {
  public:
    C() = default;
    ~C() = default;

    void Run()
    {
      std::vector<long long> Ai = {};
      std::vector<long long> Bi = {};

      int N = {};
      int M = {};
      long long K = {};
      std::cin >> N;
      std::cin >> M;
      std::cin >> K;
      Ai.reserve(N_MAX);
      Bi.reserve(N_MAX);

      long long Asum = 0;
      long long Bsum = 0;
      Ai.push_back(Asum);
      Bi.push_back(Bsum);
      for (int i = 0; i < N; ++i)
      {
        int v;
        std::cin >> v;
        Asum += v;
        Ai.push_back(Asum);
      }
      for (int i = 0; i < M; ++i)
      {
        int v;
        std::cin >> v;
        Bsum += v;
        Bi.push_back(Bsum);
      }

      int answer = 0;

      int maxB = M;
      for (int i = 0; i <= N; ++i)
      {
        long long rest = K - Ai.at(i);
        if (rest < 0) break;

        while (Bi.at(maxB) > rest && maxB>0) { maxB--; }


        int this_score = i + maxB;
        answer = this_score > answer ? this_score : answer;
      }

      std::cout << answer << std::endl;
    }
  };

}
int main()
{

  ABC172::C prob;
  prob.Run();

  return 0;
}




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


int main(){
    int K, A, B;
    cin >> K >> A >> B;
    for(int i = A; i <= B; i++){
        if(i % K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
}

Measured memory_bytes: 3636
def p(x):
 for i in[2,3,5,7,9,11,13,17,19,21,23]:
  if x%i==0:return [1,0][x>i]
 i=29
 while i<=x**.5:
  if x%i==0:return 0
  i+=2
 return 1
n=int(input())
print(sum([p(int(input()))for _ in range(n)]))

Measured memory_bytes: 5748
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    int b[n];
    int c[n-1];
    for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(int i=0;i<n;i++)
    scanf("%d",&b[i]);
    for(int i=0;i<n-1;i++)
    scanf("%d",&c[i]);
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=b[a[i]-1];
       // printf("%d    %d\n",i,sum);
        if(i!=0 && (a[i]-1)==a[i-1]){
            sum+=c[a[i-1]-1];

           // printf(" .%d. ",c[a[i-1]]);
        }
      //  printf("%d   %d\n",i,sum);
    }
    printf("%d",sum);
}

Measured memory_bytes: 1708
def main():
    cnt = 0
    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i in range(1, n+1):
        if same(i, p[i]):
            cnt += 1
    print(cnt)
        
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    x = root(x)
    if x != root(y):
        par[x] = y

if __name__ == "__main__":
    n, m = map(int, input().split())
    p = [0] + list(map(int, input().split()))
    par = list(range(n+1))
    main()


Measured memory_bytes: 122988
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];

  int max_val = *max_element(v.begin(), v.end());
  int min_val = *min_element(v.begin(), v.end());

  cout << max_val - min_val << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int sum=0;
  vector<int> time(n);
  for(int i=0;i<n;i++){
    cin>>time[i];
    sum+=time[i];
  }
  int m;
  cin>>m;
  vector<int> p(m);
  vector<int> x(m);
  for(int i=0;i<m;i++){
    cin>>p[i]>>x[i];
  }
  for(int i=0;i<m;i++){
    cout<<sum-time[p[i]-1]+x[i]<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n, m, i, j, t, d[1000], c[1000], dp[1001][1001];

	scanf("%d %d", &n, &m);

	for(i = 0; i < n; i++){
		scanf("%d", &d[i]);
	}

	for (i = 0; i < m; i++){
		scanf("%d", &c[i]);
	}

	for (i = 0; i <= n; i++){
		for (j = 0; j <= m; j++){
			dp[i][j] = 0x33433433;
		}
	}

	dp[0][0] = 0;
	for (i = 0; i <= n; i++){
		for (j = 1; j <= m; j++){
			if (i > 0) {
				if(dp[i][j-1] > dp[i-1][j-1] + d[i-1]*c[j-1]) dp[i][j] = dp[i-1][j-1] + d[i-1]*c[j-1];
				else dp[i][j] = dp[i][j-1];
			} else {
				dp[i][j] = dp[i][j-1];
			}
		}
	}

	printf("%d\n", dp[n][m]);

}

Measured memory_bytes: 4212
#ifndef CLASS_MODINT
#define CLASS_MODINT

#include <cstdint>

template <std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {};
	static constexpr std::uint32_t get_mod() { return mod; }
	std::uint32_t get() const { return n; }
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint inv() const { return (*this).pow(mod - 2); }
	modint pow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
};

#endif // CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using mint = modint<1000000007>;
mint comb(int x, int y) {
	mint ans = 1;
	for (int i = x - y + 1; i <= x; ++i) ans *= i;
	for (int i = 1; i <= y; ++i) ans *= mint(i).inv();
	return ans;
}
int main() {
	int N, M, K;
	cin >> N >> M >> K;
	mint XP = mint(3).inv() * (N - 1) * (N + 1) * mint(N).inv();
	mint YP = mint(3).inv() * (M - 1) * (M + 1) * mint(M).inv();
	mint ZP = (XP + YP) * mint(N * M) * mint(N * M - 1).inv();
	mint ans = comb(N * M, K) * ZP * mint(1LL * K * (K - 1) / 2);
	cout << ans.get() << endl;
	return 0;
}

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

char a[1000][1000];
int dp[1000][1000];
int main() {
	int h, w, n;
	while (scanf("%d%d%d", &h, &w, &n), h) {
		rep(i, h)rep(j, w) {
			int d; scanf("%d", &d); a[i][j] = d;
		}
		memset(dp, 0, sizeof(dp));
		dp[0][0] = n - 1;
		rep(i, h)rep(j, w) {
			if (i) {
				if (a[i - 1][j])dp[i][j] += dp[i - 1][j] / 2;
				else dp[i][j] += (dp[i - 1][j] + 1) / 2;
			}
			if (j) {
				if (a[i][j - 1])dp[i][j] += (dp[i][j - 1] + 1) / 2;
				else dp[i][j] += dp[i][j - 1] / 2;
			}
		}
		rep(i, h)rep(j, w) {
			if (dp[i][j] & 1)a[i][j] = !a[i][j];
		}
		int x = 0, y = 0;
		while (x < h&&y < w) {
			if (a[x][y])y++;
			else x++;
		}
		printf("%d %d\n", x + 1, y + 1);
	}
}

Measured memory_bytes: 8068
#include <stdio.h>

int main(void)
{
    int N;
    int i,j;
    int time=0;
    
    scanf("%d",&N);
    int A[N];
    
    for(i=0; i<N-1; i++){
        scanf("%d ",&A[i]);
    }
    scanf("%d",&A[N-1]);
    
    for(i=0; i<N-1; i++){
        if(A[i] == A[i+1]){
            time++;
            i++;
        }
    }
    
    printf("%d\n",time);
    
    return 0;
    
}


Measured memory_bytes: 128
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else if(s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2000*2000;
const char newl = '\n';

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

  ll n, m;
  cin >> n >> m;
  vl k(m), p(m);
  vvl sinv(n);
  rep(i, m) {
    cin >> k[i];
    ll num;
    rep(j, k[i]) {
      cin >> num;
      num--;
      sinv[num].push_back(i);
    }
  }
  rep(i, m) cin >> p[i];

  ll ans = 0;
  rep(i, 1 << n) {
  vl cnt(m);
    rep(j, n) if(i & (1 << j)) {
      for(ll k: sinv[j]) cnt[k]++;
    }
    bool b=1;
    rep(j, m) if(cnt[j]%2 != p[j]) b=0;
    if(b) ans++;
  }
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a,b) for (auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;

int main(void) {
    int a, b, h;
    cin >> a >> b >> h;
    cout << ((a + b) * h) /2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

ll m = 998244353;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main() {
    ll mod = 998244353;
    ll N;
    cin >> N;
    ll vec[100000];
    map<ll,ll> mp;
    for (ll i = 0;i<N;i++) {
        cin >> vec[i];
        mp[vec[i]]++;
    }
    bool ok = true;

    if (vec[0] != 0) ok = false;

    ll ans = 1;

    for (ll i = 1;i<N;i++) {
        ll a = mp[vec[i]-1];
        ans *= a;
        ans %= mod;
    }
    ans %= mod;
    if (ok) cout << ans << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 7296
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
        cout << "YES";
    else
        cout << "NO";
    return 0;
}


Measured memory_bytes: 256
def add_facs(facsA, facsB):
	for fac in facsB:
		if fac in facsA:
			facsA[fac] += facsB[fac]
		else:
			facsA[fac] = facsB[fac]
	return facsA
	
def factorize(n_init):
	facs = {}
	n = n_init
	i = 2
	while (n > 1) and (i < n):
		if n%i == 0:
			add_facs(facs, factorize(i))
			n = n//i
		else:
			i += 1
			
	if (n == i):
		facs[n] = 1
		
	return facs
	

N = int(input())

perN = 1
for i in range(2,N+1):
	perN *= i
	
res_facs = factorize(perN)
num = 1
for fac in res_facs:
	num = num * (res_facs[fac] + 1)

print(num%(10**9+7))


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N;
  cin>>N;
  N%=1000;
  cout<<(1000-N)%1000<<endl;

  return 0;
}


Measured memory_bytes: 3584
import queue

h,w=map(int,input().split())
s=[]
dist=[]
cnt=0
for i in range(h):
  s.append(input())
  dist.append([5000]*w)
  cnt+=s[i].count("#")
que=queue.Queue()
que.put([0,0])
dist[0][0]=0
d=[[0,1],[0,-1],[1,0],[-1,0]]
while not que.empty():
  place=que.get()
  for p in d:
    if -1<place[0]+p[0]<h and -1<place[1]+p[1]<w:
      if s[place[0]+p[0]][place[1]+p[1]]=="." and dist[place[0]][place[1]]+1<dist[place[0]+p[0]][place[1]+p[1]]:
        dist[place[0]+p[0]][place[1]+p[1]] = dist[place[0]][place[1]]+1
        que.put([place[0]+p[0],place[1]+p[1]])
if dist[h-1][w-1]<5000:
  print(h*w-cnt-dist[h-1][w-1]-1)
else:
  print(-1)

Measured memory_bytes: 3952
def selectionSort(A, N):
    swap_count = 0

    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        if i != minj:
            swap_count += 1

    return swap_count


if __name__ == "__main__":
    N = int(input())
    numbers = input().split(" ")
    for i in range(len(numbers)):
        numbers[i] = int(numbers[i])

    swap_count = selectionSort(numbers, N)

    print(*numbers)
    print(swap_count)


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

public class Program
{

    public void Proc()
    {
        this.NumList = Reader.ReadLine().Select(a => int.Parse(a.ToString())).ToArray();

        List<bool> ansList = GetAns(0, this.NumList[0], new List<bool>());

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < NumList.Length; i++) {
            ans.Append(NumList[i]);
            if(i<NumList.Length - 1) {
                ans.Append(ansList[i]?"+":"-");
            }
        }
        ans.Append("=7");
        Console.WriteLine(ans.ToString());
    }

    private int[] NumList;

    private List<bool> GetAns(int idx, int subTotal, List<bool> subList) {
        if(idx>=3) {
            if(subTotal == 7) {
                return subList;
            } else {
                return null;
            }
        }

        List<bool> subSubList = new List<bool>(subList);
        subSubList.Add(true);
        List<bool> tmp = GetAns(idx + 1, subTotal + NumList[idx + 1], subSubList);
        if(tmp != null) {
            return tmp;
        }
        subSubList = new List<bool>(subList);
        subSubList.Add(false);
        tmp = GetAns(idx + 1, subTotal - NumList[idx + 1], subSubList);
        return tmp;
    } 

    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



0290



";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


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

#define int long long

main()
{
  int n;
  string s;
  int cnt = 0;
  int leftadd = 0, rightadd = 0;
  
  cin >> n >> s;

  for(int i = 0; i < n; i++) {
    if(s[i] == ')') {
      if(cnt == 0) leftadd++;
      else cnt--;
    }
    
    if(s[i] == '(') cnt++;
  }
  
  cnt = 0;
  for(int i = n - 1; i >= 0; i--) {
    if(s[i] == '(') {
      if(cnt == 0) rightadd++;
      else cnt--;
    }

    if(s[i] == ')') cnt++;
  }

  for(int i = 0; i < leftadd; i++) cout << "(";
  cout << s;
  for(int i = 0; i < rightadd; i++) cout << ")";
  cout << endl;

  return (0);
}

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

int main()
{
	int n; cin >> n;
	vector <int> v;
	for (int i = 0, x; i < n; i++)
	{
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	cout << v[n/2] - v[n/2-1];
	return 0;
}
	

Measured memory_bytes: 892
n,d=map(int,input().split())
x = [list(map(int, input().split())) for _ in range(n)] 

ans=0

for i in range(n):
    for j in range(i+1,n):
        wrk=0    
        for k in range(d):
            #print(i,j,k)
            wrk+=(x[i][k]-x[j][k])**2
        #print(wrk**0.5)
        if wrk**0.5%1==0:
            ans+=1
print(ans)

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

typedef struct  s_p
{
    int n;
    int i;
}               t_p;

int compare_ints(const void* a, const void* b)
{
    t_p arg1 = *(const t_p*)a;
    t_p arg2 = *(const t_p*)b;
 
    if (arg1.n < arg2.n) return -1;
    if (arg1.n > arg2.n) return 1;
    return 0;
}

int	main(void)
{
  	int	N;
  	t_p A[100010];
  	int	num;
  	int i;
  	int tmp;
  
  	num = scanf("%d\n", &N);
  	if (num != 1)
      	return (0);
  
  	for (i=0; i<N; i++)
    {
      	num = scanf("%d", &A[i].n);
      	if (num != 1)
          	return (0);
        A[i].i = i+1;
    }
  
    qsort(A, N, sizeof(t_p), compare_ints);
    
    for (i=0; i<N; i++)
    {
        if (A[i].n == 1)
        {
            tmp = i;
            break ;
        }
    }
    
    for (i=0; i<N; i++)
    {
            printf("%d ", A[i].i);
    }

  	return (0);
}
          

Measured memory_bytes: 1788
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n ;
    cin >> n ;
    string s ;
    cin >> s ;
    int cnt = 0 ;
    for(char &c : s){
        if ( c == 'R' ) cnt++ ;
    }
    int ans = 0 ;
    for(int i = 0; i < cnt; i++){
        if ( s[i] == 'W' ) ans++ ;
    }
    cout << ans << endl;
    return 0; 
}


Measured memory_bytes: 3752
//B Buffet
#include <iostream>
#include <vector>

int main()
{
    int n;
    std::cin >> n;

    //input
    std::vector<int> A(n,0);
    for(int i = 0; i < n; i++)
    {
        std::cin  >> A.at(i);
        A.at(i)--;
    }

    std::vector<int> B(n, 0);
    for(int i = 0; i < n; i++)
    {
        std::cin >> B.at(i);
    }

    std::vector<int> C(n, 0);
    for(int i = 0; i < n-1; i++)
    {
        std::cin >> C.at(i);
    }

    int totalB = 0;
    for(int i = 0; i < n; i++)
    {
        totalB += B.at(A.at(i));
        if(i > 0)
        {
            if(A.at(i) - 1 == A.at(i - 1))
            {
                totalB += C.at(A.at(i - 1));
            }
        }
    }

    std::cout << totalB << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
using namespace std;
typedef long long ll;
ll dist[300][300];
int main()
{
	int n,m;
	ll l;
	cin>>n>>m>>l;
	fill(dist[0],dist[300],1e14-1);
	for(int i=0;i<n;i++)
		dist[i][i]=0;
	for(int i=0;i<m;i++)
	{
		int a,b;
		ll c;
		cin>>a>>b>>c;
		a--;b--;
		if(c>l)
			continue;
		dist[a][b]=min(dist[a][b],c);
		dist[b][a]=min(dist[b][a],c);
	}
	//wf
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(dist[i][j]<=l)
				dist[i][j]=1;
			else
				dist[i][j]=1e14-1;
		}
	}
	//wf2
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		}
	}
	int q;
	cin>>q;
	for(int i=0;i<q;i++)
	{
		int s,t;
		cin>>s>>t;
		s--;t--;
		if(dist[s][t]==1e14-1)
			cout<<-1<<endl;
		else
			cout<<dist[s][t]-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cstdlib>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

typedef long long ll;
const int Max = 1e6;
using namespace std;

int main(){
	int i, j, n, m, k;
	ll ans;
	while(~scanf("%d", &n)){
		int a[11];
		for(i = 0; i < n; i++)  scanf("%d", &a[i]);
		sort(a, a + n, greater<int>());
		ans = a[0] / 2;
		for(i = 1; i < n; i++) ans += a[i];
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;
using graph = mat;
using edge = pair<ll,ll>;
using wgraph = vector<vector<edge>>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll A, B, N;
    cin >> A >> B >> N;

    if(B - 1 <= N) _PR(A*(B-1)/B);
    else _PR(A*N/B);

    return 0;
}

/*



*/

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int n, k, x, y;

int32_t main()
{
	IOS;
	cin>>n>>k>>x>>y;
	int ans=min(n, k) * x + max(0LL, n-k) * y;
	cout<<ans;
  	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

// #define int ll

const int maxn = 1e5+5;
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}


main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n; cin>>n;
    vector<int> a(n), b(n);
    REP(i,n) cin>>a[i];
    REP(i,n) cin>>b[i];
    ll x = 0;
    REP(i,n){
    	if (a[i]-b[i]>0) x+=a[i]-b[i];
    }
    cout<<x<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    if(n>k){
        n = n%k;
    }
    ll ans = n;
    chmin(ans, abs(n-k));
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

ll N;
ll A[(int)1e5];

int main() {
    cin >> N;
    rep(i, N) cin >> A[i];

    map<ll, ll> mp;
    rep(i, N) {
        mp[A[i]]++;
    }

    vector<ll> v;
    ll square_max = 0;
    for (auto iter = mp.begin(); iter != mp.end(); iter++) {
        if (iter->second >= 2) {
            v.push_back(iter->first);
        }

        if (iter->second >= 4) {
            square_max = iter->first;
        }
    }

    // 長方形を作れない場合
    if (v.size() < 2 && square_max == 0) {
        cout << 0 << endl;
        return 0;
    }

    if (square_max == v[v.size() - 1]) {
        cout << square_max * square_max << endl;
    } else {
        cout << v[v.size() - 1] * v[v.size() - 2] << endl;
    }
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VL A(N);
  rep(i,N) cin>>A[i];
  int F=0;
  ll ans=1;
  rep(i,N) if(A[i]==0) F=1;
  if(F){
    cout<<0<<endl;
    return 0;
  }
  rep(i,N){
    if(1000000000000000000/ans<A[i]){
      F=1;
      break;
    }else ans*=A[i];
  }
  if(F) cout<<-1<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 4028
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n, c = map(int, input().split())
    c_info = [[int(i) for i in input().split()] for _ in range(n)]
    c_info.sort(key=lambda x: (x[2], x[0]))
    info = []
    cnt = 0
    
    while cnt < n:
        if cnt == n - 1:
            info.append(c_info[cnt])
            break
        if c_info[cnt][1] == c_info[cnt + 1][0] and c_info[cnt][2] == c_info[cnt + 1][2]:
            tc = c_info[cnt][2]
            t = [c_info[cnt][0], c_info[cnt + 1][1], tc]
            cnt += 1
            while cnt < n - 1 and t[1] == c_info[cnt + 1][0] and tc == c_info[cnt + 1][2]:
                t = [t[0], c_info[cnt + 1][1], tc]
                cnt += 1
            info.append(t)
            if cnt == n - 1:
                break
        else:
            info.append(c_info[cnt])
        cnt += 1

    tarr = [0] * (2 + 10 ** 5)
    for elem in info:
       tarr[elem[0]] += 1
       tarr[elem[1] + 1] -= 1
    
    ans = 1
    tans = 0
    for elem in tarr:
        tans += elem
        ans = max(ans, tans)
    print(ans)

if __name__=="__main__":
    solve()


Measured memory_bytes: 29216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		sc.close();

		int a = N / 1000;
		int b = (N % 1000) / 100;
		int c = (N % 100) / 10;
		int d = (N % 100) % 10;

		if(a == b && b == c && c == d) {
			System.out.println("Yes");
		}else if(a == b && b == c) {
			System.out.println("Yes");
		}else if(b == c && c == d) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}
}

Measured memory_bytes: 23252
#include<stdio.h>

long long n, a[100001], b[100000], ans = 0, i, j;

int main(void) {
	scanf("%lld", &n);
	for (i = 0; i < n + 1; i++) {
		scanf("%lld", &a[i]);
	}
	for (j = 0; j < n; j++) {
		scanf("%lld", &b[j]);
	}
	for (i = 0; i < n; i++) {
		if (a[i] >= b[i]) {
			ans += b[i];
			b[i] = 0;
		}
		else {
			ans += a[i];
			b[i] -= a[i];
		}
		if (a[i + 1] >= b[i]){
			ans += b[i];
			a[i + 1] -= b[i];
		}
		else {
			ans += a[i + 1];
			a[i + 1] = 0;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1664
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    ll h, w, ans;
    cin >> h >> w;
    if(h == 1 || w == 1){
        ans = 1;
    }else{
        ans = h / 2 * w + h % 2 * ceil(w / 2.0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int D, T, S;
	cin >> D >> T >> S;
	if (T * S >= D)
	    cout << "Yes";
	else
	    cout << "No";

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int n, arr[210], odd=0;
int aux[210], mini = 1000000;


int main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &arr[i]);
        while(arr[i] %2 == 0){
            arr[i] = arr[i]/2;
            aux[i] += 1;
        }
    }

    for(int i=0; i<n; i++){
        if(aux[i] < mini)
            mini = aux[i];
    }
    printf("%d\n", mini);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
 int N,A,B;
  cin>>N>>A>>B;
  while(1){
  	if(A+1==B){
      A--;
      if(A==0){
        cout<<"Borys"<<endl;
        break;
      }
    }else A++;
    
    if(B-1==A){
      B++;
      if(B==N+1){
      	cout<<"Alice"<<endl;
        break;
      }
    }else B--;
  }
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	ll x, y;
	cin >> x >> y;
	ll ans = 0;
	for(ll i = x; i <= y; i *= 2){
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] A = new int[n];
		int[] left = new int[n];
		int[] right = new int[n];
		for(int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}
		int ans = 0;
		left[0] = 0;
		for(int i = 1; i < n; i++) {
			left[i] = gcd(left[i-1], A[i-1]);
		}
		right[n-1] = 0;
		for(int i = n-2; i >= 0; i--) {
			right[i] = gcd(right[i+1], A[i+1]);
		}
		for(int i = 0; i < n; i++) {
			ans = Math.max(ans, gcd(left[i], right[i]));
		}
		//クラスにしないでL、Rをmain内に配列として入れるプランに変更
		
		System.out.println(ans);
		sc.close();
	}
	private static int gcd(int m, int n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
	
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long N, std::vector<long long> P, std::vector<long long> Q){
    Vi R=P;
    sort(ALL(R));
    int p,q,count=0;
    do{
        if(R==P) p=count;
        if(R==Q) q=count;
        count++;
    }while(next_permutation(ALL(R)));
    cout<<abs(p-q)<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    std::vector<long long> Q(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
    return 0;
}


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 pll=pair<ll,ll>;
using tll=tuple<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 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 OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,a,b,ans=0;
	cin>>n>>m;
	vvb e(n,vb(n,false));
	rep(i,m){
		cin>>a>>b;
		a--;b--;
		e[a][b]=true;
		e[b][a]=true;
	}
	vl v(n);
	iota(all(v),0);
	do{
		if(v[0]!=0)break;
		bool ok=true;
		rep(i,n-1){
			if(!e[v[i]][v[i+1]])ok=false;
		}
		if(ok)ans++;
	}while(next_permutation(all(v)));
	cout<<ans<<endl;
}


Measured memory_bytes: 256