akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end



int main(){
   string s; cin>>s;
   printf(s[2]==s[3]&&s[4]==s[5]?"Yes":"No");
   return 0;
}

Measured memory_bytes: 256
import math
N,K=map(int,input().split())
p=list(map(int,input().split()))
bufexp=0
exp=0
buf=0
max=0
for i in range(K):
    buf=buf+p[i]
    bufexp=bufexp+(1+p[i])/2
left=p[0]
#print(bufexp)
#print(bufexp,buf)
for i in range(N-K):
    if buf>max:
        #print(i,bufexp)
        exp=bufexp
        max=buf
    bufexp=bufexp-((1+left)/2)+((1+p[i+K])/2)
    buf=buf-left+p[i+K]
    left=p[i+1]
    #print(i,bufexp,buf)
if buf>max:
    print(bufexp)
else:
    print(exp)

Measured memory_bytes: 71792
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MOD = 1E9 + 7;

int Add(int a, int b, int m = MOD){
  a += b;
  if(a >= m) a -= m;
  return a;
}

int Sub(int a, int b, int m = MOD){
  a -= b;
  if(a < 0) a += m;
  return a;
}

int AddTo(int& to, int w, int m = MOD){
  to += w;
  if(to >= m) to -= m;
  return to;
}

int SubTo(int& to, int w, int m = MOD){
  to -= w;
  if(to < 0) to += m;
  return to;
}

int Mult(int a, int b, int m = MOD){
  return (a * 1LL * b) % m;
}

// Sol
int Fact(int w){
  int res = 1;
  for(int i = 2;i <= w;++i)
    res = Mult(res, i);
  return res;
}

int main(){
  int a, b, ans = 0;
  cin >> a >> b;

  if(a > 0 && (a == b || a == b + 1))
    AddTo(ans, Mult(Fact(a), Fact(b)));
  if(b > 0 && (a == b || a + 1 == b))
    AddTo(ans, Mult(Fact(a), Fact(b)));

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  long n,k,r,s,p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  vector<string> data(k);
  rep(i,n){
    data.at(i%k).push_back(t.at(i));
  }
  //rep(i,k) cout << data.at(i) << endl;
  //map<char,int> mp;
  //mp['r'] = 2;
  //mp['s'] = 0;
  //mp['p'] = 1;
  
  //vector<vector<long>> dp(n+1,vector<long>(3,0));
  
  /*rep(i,k){
    dp.at(i+1)
  }*/
  
  long ans = 0;
  rep(i,k){
    long len = data.at(i).size();
    vector<vector<long>> dp(len+1,vector<long>(3,0));
    for(int j=1;j<=len;j++){
      char tmp = data.at(i).at(j-1);
      if(tmp == 's'){
        dp.at(j).at(0) = max(dp.at(j-1).at(1),dp.at(j-1).at(2)) + r;
        dp.at(j).at(1) = max(dp.at(j-1).at(2),dp.at(j-1).at(0));
        dp.at(j).at(2) = max(dp.at(j-1).at(1),dp.at(j-1).at(0));
      }
      if(tmp == 'p'){
        dp.at(j).at(0) = max(dp.at(j-1).at(1),dp.at(j-1).at(2));
        dp.at(j).at(1) = max(dp.at(j-1).at(2),dp.at(j-1).at(0)) + s;
        dp.at(j).at(2) = max(dp.at(j-1).at(1),dp.at(j-1).at(0));
      }
      if(tmp == 'r'){
        dp.at(j).at(0) = max(dp.at(j-1).at(1),dp.at(j-1).at(2));
        dp.at(j).at(1) = max(dp.at(j-1).at(2),dp.at(j-1).at(0));
        dp.at(j).at(2) = max(dp.at(j-1).at(1),dp.at(j-1).at(0)) + p;
      }
    }
    ans += max(dp.at(len).at(0),max(dp.at(len).at(1),dp.at(len).at(2)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 5888
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define mp make_pair

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
    return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
    return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
    int sign = 1;
    T ret = 0;
    char c;

    do{
        c = getc();
    }while(c == ' ' || c == '\n');
    if(c == '-')sign = -1;
    else ret = c-'0';
    while(1){
        c = getc();
        if(c < '0' || c > '9')break;
        ret = 10*ret + c-'0';
    }
    return sign * ret;
}

inline void ini(int& x){
    x = getnum<int>();
}

inline void scani(int& x){
    scanf("%d",&x);
}

//end of macro

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    int n;
    cin>>n;
    int ans = 0;
    REP(i,1,n){
        int a,b;
        cin>>a>>b;
        ans += b-a+1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  ll cnt = 0;
  map<int,int> m;
  REP(i,n) {
    int a;
    cin>>a;
    cnt += m[-a + i+1];
    ++m[a + i+1];
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 20560
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
int main() {
	ll n, count = 0;
	cin >> n;
	ll x = n;
	while (x > 0) {
		count += x % 10;
		x /= 10;
	}
	if (n%count == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(lli N, lli K, vector<int> const &A) {
  vector<bool> visited(N, false);
  int x = 0;
  int ltot = 0;
  while (!visited[x]) {
    visited[x] = true;
    x = A[x];
    ++ltot;
  }

  int const st = x;
  int linit = 0;
  for (x = 0; x != st; ++linit) {
    x = A[x];
  }

  int const lloop = ltot - linit;
  K = (K - linit) % lloop + linit;
  x = 0;
  for (lli i = 0; i < K; ++i) {
    x = A[x];
  }

  cout << x+1 << endl;
}

int main() {
  // cout << fixed << setprecision(10);

  lli N;
  lli K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    --A[i];
  }
  if (K <= 2 * N) {
    int x = 0;
    for (lli i = 0; i < K; ++i) {
      x = A[x];
    }
    cout << x+1 << endl;
    return 0;
  }
  solve(N, K, A);
  return 0;
}


Measured memory_bytes: 4052
#include <cstdio>
#include <vector>

int main()
{
  int m;
  scanf("%d",&m);
  std::vector<int> d(m);
  std::vector<long long> c(m);
  for(int i=0;i<m;i++){
    scanf("%d%lld",&d[i],&c[i]);
  }
  int cur=d[0],t;
  if(c[0]==1){
    t=1;
  }
  else{
    c[0]--;
    t=0;
  }
  long long ans=0;
  for(;t<m;t++){
    int rem=cur;
    int L=0,l=0;
    while(c[t]>0){
      int g=(cur+d[t])%9;
      if(g==0)
	g=9;
      int w=(cur+d[t])>=10?2:1;
      ans+=w;
      L+=w;
      l++;
      c[t]--;
      if(g==rem){
	ans+=(c[t]/l)*L;
	c[t]%=l;
      }
      cur=g;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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


Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>

using namespace std;

int N, M;
int edge[700][700];
int A, B;
int p;

int team[700];
int num_team[2];
int a[700], b[700];
queue<int> qu;
int q;

int dp[701][701];

int min_unchecked(void) {
	for (int i = 0; i < N; i++) {
		if (team[i] == -1) { return i; }
	}
	return N;
}

int main(void) {
	/*まず辺のあるなしを逆にしておく*/
	scanf("%d %d", &N, &M);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			edge[i][j] = 1;/*まず全部つないでおく*/
		}
	}

	for (int i = 0; i < N; i++) {
		edge[i][i] = 0;
	}

	for (int i = 0; i < M; i++) {
		scanf("%d %d", &A, &B);
		edge[A - 1][B - 1] = 0;
		edge[B - 1][A - 1] = 0;
	}

	/*各連結成分ごとに、2つに分けたときにいくつずつになるのか調べる*/

	for (int i = 0; i < N; i++) {
		team[i] = -1;
	}

	int pt = 0;

	while (1) {
		p = min_unchecked();
		if (p == N) { break; }

		num_team[0] = 0;
		num_team[1] = 0;

		team[p] = 0;
		num_team[0]++;



		qu.push(p);
		while (qu.empty() == 0) {
			q = qu.front();
			qu.pop();
			for (int i = 0; i < N;i++){
				if (edge[q][i] == 0) { continue; }
				if(team[i] == -1){
					qu.push(i);
					team[i] = 1 - team[q];
					num_team[team[i]]++;
				}
				if (team[i] == team[q]) {
					printf("-1\n");
					return 0;
				}
			}
		}
		a[pt] = num_team[0];
		b[pt] = num_team[1];
		pt++;
	}

	/*
	for (int i = 0; i < pt; i++) {
		printf("%d %d\n", a[i], b[i]);
	}
	*/

	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		dp[0][i] = 0;
	}

	for (int i = 1; i <= N; i++) {
		for (int c = 1; c <= pt; c++) {
			dp[c][i] = 0;
		}
	}

	for (int c = 1; c <= pt; c++) {
		for(int i = 0; i <= N; i++) {
			if (i - a[c - 1] >= 0) {
				if (dp[c - 1][i - a[c - 1]] == 1) {
					dp[c][i] = 1;
				}
			}
			if (i - b[c - 1] >= 0) {
				if (dp[c - 1][i - b[c - 1]] == 1) {
					dp[c][i] = 1;
				}
			}
		}
	}

	/*
	for (int c = 0; c <= pt; c++) {
		for (int i = 0; i <= N; i++) {
			printf("dp[%d][%d] = %d\n", c, i, dp[c][i]);
		}
	}
	*/
	int MM;
	MM = 0;
	for (int i = 0; i <= N/2; i++) {
		if (dp[pt][i] == 1) {
			MM = i;
		}
	}

	printf("%d\n", (MM*(MM - 1)) / 2 + ((N - MM)*(N - MM - 1)) / 2);

}









Measured memory_bytes: 4096
import numpy as np

N = int(input())

point = [[int(item) for item in input().split()] for _ in range(N)]
point.sort(key=lambda x:x[2], reverse=True)

ans = np.zeros((101, 101))

for i, p in enumerate(point):
  if i == 0:
    for j in range(101):
      for k in range(101):
        H = p[2] + abs(j - p[0]) + abs(k - p[1])
        ans[j, k] = H
  else:
    for j in range(101):
      for k in range(101):
        if not ans[j,k] == 0:
          if ans[j,k] != p[2] + abs(j - p[0]) + abs(k - p[1]):
            ans[j,k] = 0
  if len(ans[ans!=0]) <= 1:
    break

x, y = np.where(ans!=0)
print(x[0], y[0], int(ans[x[0],y[0]]))
      
  

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

int main() {
    string b;
    cin >> b;

    if (b == "A") {
        cout << "T" << endl;
    } else if (b == "C") {
        cout << "G" << endl;
    } else if (b == "G") {
        cout << "C" << endl;
    } else if (b == "T") {
        cout << "A" << endl;
    }

}


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

int main() {
 int X, A, B;
 cin >> X >> A >> B;
 
 if ( A >= B ) cout << "delicious" << endl;
 else if ( B > A && X + A >= B ) cout << "safe" << endl;
 else cout << "dangerous" << endl;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define ull unsigned long long int
#define T int test; scanf("%d",&test); while(test--)
#define pb push_back
#define in insert
#define PI acos(-1)
#define sc(n) scanf("%d",&n)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define lsc(n) scanf("%lld",&n)
#define lsc2(a,b) scanf("%lld%lld",&a,&b)
#define rep(i,n) for(i=0;i<n;i++)
#define fr(i,a,b) for(i=a;i<b;i++)
#define gcd(a,b) __gcd(a,b)
#define gcd3(a,b,c) __gcd(__gcd(a,b),c)
#define lcm(a,b) (a*b)/__gcd(a,b)
using namespace std;

ll h,i=1;
void solve(ll h)
{
	//cout << h << " " << i << endl;
	if(h==1)
	{
		i=pow(2,i)-1;
		cout << i << endl;
		return;
	}
		
	else
	{
		i++;
		return solve(h/2);
	}
}

int main()
{
	lsc(h);
	solve(h);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> c(n),s(n),f(n);
    rep(i,0,n-1) cin>>c[i]>>s[i]>>f[i];
    
    rep(i,0,n){
        int now=0;
        rep(j,i,n-1){
            while(now%f[j]!=0) now++;
            now=max(now,s[j]);
            now+=c[j];
        }
        cout<<now<<endl;
    }
    
}


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

void push(int);
int pop();

int Stack[199];
int i = 0;

int main()
{
  int num1,num2,num;
  char c[199];
  while(scanf("%s",c) != EOF){
    if((c[0] >= '0') && (c[0] <= '9')){
      push(atoi(c));
    }
    else if(c[0] == '*'){
      num1 = pop();
      num2 = pop();
      num = num2*num1;
      push(num);
    }
    else if(c[0] == '+'){
      num1 = pop();
      num2 = pop();
      num = num2+num1;
      push(num);
    }
    else if(c[0] == '-'){
      num1 = pop();
      num2 = pop();
      num = num2-num1;
      push(num);
    }
  }
  printf("%d\n",num);
  return 0;
}

void push(int num){
  Stack[i] = num;
  i++;
}

int pop(){
  int num;
  i--;
  num = Stack[i];
  return num;
}



Measured memory_bytes: 2052
#include <stdio.h>
#include <string.h>

void suffle(char* str, int h);

int main(void)
{
  char str[201];
  int count, i,h;

  scanf("%s", str);


  while(strcmp(str, "-")!=0) {
      scanf("%d", &count);
    for(i=0;i<count;i++) {
      scanf("%d", &h);
      suffle(str, h);
    }
    printf("%s\n", str);
    scanf("%s", str);
  }

  return 0;
}

void suffle(char* str, int h)
{
  char ue[201], shita[201];
  strcpy(shita, str);
  strcpy(ue, str+h);
  shita[h] = '\0';
  strcpy(str, ue);
  strcat(str, shita);
}

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

string s, u, c;
int q, t, f;
bool g = 1;

int main()
{
	cin >> s >> q;

	for (int i = 0; i < q; i++) {
		cin >> t;

		if (t == 1)
			g = !g;
		else if (t == 2) {
			cin >> f >> c;

			if ((g && f == 2) || (!g && f == 1))
				s += c;
			else
				u += c;
		}
	}

	if (g) {
		for (int i = u.size() - 1; i >= 0; i--)
			cout << u[i];
		cout << s << endl;
	}
	else {
		for (int i = s.size() - 1; i >= 0; i--)
			cout << s[i];
		cout << u << endl;
	}
}


Measured memory_bytes: 964
<?php 
    fscanf(STDIN,"%d %d", $hitpoint, $attack);
    $list = explode(" ",trim(fgets(STDIN)));

    $total_attak_power = array_sum($list);
    
    if($hitpoint <= $total_attak_power) {
        echo "Yes";
    } else {
        echo "No";
    }

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;

template<typename T1,typename T2> using M = map< T1, T2>;
using Mpi = M<Pii, int>;

const int MOD = 1000000007;

/* graph */
struct edge{
    int src; int dst; int weight;
    edge() : src(0), dst(0), weight(0) {}
    edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};

using edges = V<edge>;
using graph = V<edges>;

void add_edge(edges &g,int s, int d, int w=1){g.pb(edge(s,d,w));}
void add_edge(graph &g,int s, int d, int w=1){g[s].pb(edge(s,d,w));}

int main(){
    int n;
    cin>>n;
    Vi a(n),b(n);
    graph G(n);
    Mpi C;
    REP(i,n-1){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        add_edge(G,a[i],b[i]);
        add_edge(G,b[i],a[i]);
        C[mp(a[i],b[i])] = -1;
    }

    int max_deg = 0;
    int max_v = -1;
    REP(i,n){
        if(max_deg < G[i].size()){
            max_deg = G[i].size();
            max_v = i;
        }
    }

    Vi visit(n,0);
    queue<Pii> q;
    q.push(mp(max_v,-1));
    while(!q.empty()){
        Pii tmp = q.front();
        int now_v = tmp.fi;
        int pre_c_id = tmp.se;
        visit[now_v] = 1;
        q.pop();
        int c_id = 0;
        for(edge &e: G[now_v])
        {
            if(c_id == pre_c_id) c_id++;
            int next_v = e.dst;
            if(visit[next_v]==1) continue;
            auto it_1 = C.find(mp(now_v,next_v));
            if(it_1 != C.end()){
                it_1->se = c_id;
            }else{
                auto it_2 = C.find(mp(next_v,now_v));
                if(it_2 != C.end()){
                    it_2->se = c_id;
                }
            }
            q.push(mp(next_v,c_id));
            c_id++;
        }
    }

    cout<<max_deg<<endl;
    REP(i,n-1){
        cout<<C[mp(a[i],b[i])]+1<<endl;
    }


    return 0;
}

Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	int a,b;
	char op;
	cin >> a >> op >> b;
	if(op=='+')
	{
		cout<<a+b<<endl;
	}
	else
	{
		cout<<a-b<<endl;
	}
	
}

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

int main(){
  int n;
  cin>>n;
  int tarous=0,hanakos=0;
  for(int i=0;i<n;i++){
    string tarou,hanako;
    cin>>tarou>>hanako;
    if(tarou>hanako){
      tarous+=3;
    }else if(tarou<hanako){
      hanakos+=3;
    }else{
      tarous++;
      hanakos++;
    }
  }
  cout<<tarous<<' '<<hanakos<<endl;
  return 0;
}




Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));


int main(){	
	long long E;
	long long D;
	long long C;
	long long B;
	long long A;
	long long F;
	scanf("%lld",&A);
	scanf("%lld",&B);
	scanf("%lld",&C);
	scanf("%lld",&D);
	scanf("%lld",&E);
	scanf("%lld",&F);
	ll n = 0, d = A*100;
	rep(i, F/100+1) {
		rep(j, (F-100*A*i)/100+1) {
			rep(k, (A*i+B*j)*E/C+1) {
				ll l = max(min(((A*i+B*j)*E-C*k)/D, (F-100*A*i-100*B*j-C*k)/D), 0LL);
				if (C*k+D*l > E*(A*i+B*j) || 100*A*i+100*B*j+C*k+D*l > F || i+j == 0) continue;
				if (n*(100*A*i+100*B*j+C*k+D*l) < d*(C*k+D*l)) {
					n = C*k+D*l;
					d = 100*A*i+100*B*j+C*k+D*l;
				}
				// printf("%lld %lld %lld %lld: %lld %lld\n", i, j, k, l, d, n);
			}
		}
	}
	cout << d << " " << n << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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 PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n; cin >> n;
    if (n == 1) cout << "Hello World" << endl;
    else
    {
        int a, b; cin >> a >> b;
        cout << a + b << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <limits.h>
#include <numeric>
#include <math.h>
#include <bits/stdc++.h>
#define rep(i,c) for (int i=0;i<c;i++)
using namespace std;
typedef long long ll;
 
 
int main(){
    int N;
    cin >> N;
    int a[109];
    rep(i,N) cin >> a[i];
    sort(a,a+N,greater<>());
    int bob=0;
    int alice = 0;

    rep(i,N){
        if(i%2==0) alice += a[i];
        else bob += a[i];
    }

    cout << alice - bob << endl;


}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val p = (0 until n).map { sc.next().toInt() }
    val q = (0 until n).map { sc.next().toInt() }
    println(problem150c(n, p, q))
}

fun problem150c(n: Int, p: List<Int>, q: List<Int>): Int {
    /**
     * 辞書順で順列の次の組み合わせにarrayを書き換える
     */
    fun nextPermutation(array: IntArray): Boolean {
        var i = array.size - 1
        while (i > 0 && array[i - 1] >= array[i]) i--
        if (i <= 0) return false
        var j = array.size - 1
        while (array[j] <= array[i - 1]) j--
        var temp = array[i - 1]
        array[i - 1] = array[j]
        array[j] = temp
        j = array.size - 1
        while (i < j) {
            temp = array[i]
            array[i] = array[j]
            array[j] = temp
            i++
            j--
        }
        return true
    }
    val p = p.toIntArray()
    val q = q.toIntArray()
    val nArray = (1..n).toList().toIntArray()
    var last = true
    var a = 0
    var b = 0
    var count = 1
    while (last) {
        if (nArray.joinToString("") == p.joinToString("")) a = count
        if (nArray.joinToString("") == q.joinToString("")) b = count
        last = nextPermutation(nArray)
        count++
    }
    return Math.abs(a - b)
}

Measured memory_bytes: 49060
N = int(input())
H = list(map(int, input().split()))
ans = 0
count = []
for i in range(N - 1):
    if H[i] - H[i + 1] >= 0:
        ans += 1
        count.append(ans)
    if H[i] - H[i + 1] < 0:
        ans = 0
count.sort()
if count:
    print(count[-1])
else:
    print(0)

Measured memory_bytes: 14224
#include <stdio.h>

int main(void) {
	int i;
	int ans;
	char s[7];

	scanf("%s", s);

	ans = 0;
	for (i = 0; i < 6; i++)
		ans += s[i] == '1';

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;
using ll=long long;


int main() {
  int x;
  cin >> x;
  if (x==2){cout << x; return 0;}

  while(true){
    int a=(int)pow(x,0.5)+1;
    for(int i=2;i<=a;i++){
      if(!(x%i)) {
        x++;break;
      }
      if(i==a){
        cout << x;
        return 0;
      }
    }
  }
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

struct st{
	int x,y,k;P c;
};
bool operator<(st a,st b){
	return a.c>b.c;
}

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

int main(){
	int h,w,K;
	cin>>h>>w>>K;
	int sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy;
	sx--;sy--;gx--;gy--;
	vector<string>s(h);
	rep(i,h){
		cin>>s[i];
	}
	vector<vector<vector<P>>>d(h,vector<vector<P>>(w,vector<P>(5,P(INF,INF))));
	priority_queue<st>que;
	d[sx][sy][4]=P(0,0);
	que.push({sx,sy,4,P(0,0)});
	while(!que.empty()){
		st p=que.top();que.pop();
		if(d[p.x][p.y][p.k]!=p.c)continue;
		rep(k,4){
			int nx=p.x+dx[k],ny=p.y+dy[k];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&s[nx][ny]!='@'){
				P cost=p.c;
				if(k==p.k&&cost.second<K)cost=P(cost.first,cost.second+1);
				else cost=P(cost.first+1,1);
				if(d[nx][ny][k]>cost){
					d[nx][ny][k]=cost;
					que.push({nx,ny,k,cost});
				}
			}
		}
	}
	P ans(INF,INF);
	rep(k,4){
		ans=min(ans,d[gx][gy][k]);
	}
	if(ans.first==INF)puts("-1");
	else cout<<ans.first<<endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rept(i, a, b) for(int i=a ; i<=b; i++)

int main(){
    string s; cin >> s;
    int n = s.size();
    int cnt = 0;
    for(int i=0; i<n/2 ; i++){
        if(s.at(i) != s.at(n-1-i))
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(20000)


def inpl():
    return list(map(int, input().split()))


def gcd(a, b):
    la = max(a, b)
    sm = min(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la - sm)


n = int(input())
A = inpl()
A.sort()
ans = gcd(A[0], A[1])
for a in A:
    ans = gcd(ans, a)
print(ans)


Measured memory_bytes: 19588
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define in(n) cin>>n>>
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    
     
    
    
    
    char x,y;
    
    cin >> x >> y;
    
    if((x-y)>0){
        
        cout << '>' << endl;
        
    }else if (x==y){
        
        cout << '=' << endl;
        
    }else{
        
        cout << '<' << endl;
        
    }
    
    
    /*int s[3][2];
    
    rep(i,3){
        rep(j,3){
            
            cin >> s[i][j];
            
        }
    }
    
    if ((s[0][0]==s[2][1])&&(s[1][0]==s[1][1])&&(s[2][0]==s[0][1])){
    
    cout << "Yes" << endl;
    
    }else{
    
    cout << "No" << endl;
    
    }
    */
/////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
def selections(N):
    count = 0
    for i in range(len(N)):
        mini = i
        for j in range(i+1, len(N)):
            if N[mini] > N[j]:
                mini = j
        if i != mini:
            N[mini], N[i] = N[i], N[mini]
            count += 1
    c = 1
    for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
    print('')
    print(count)
     
n = int(input())
numbers = list(map(int, input().split()))
 
selections(numbers)


Measured memory_bytes: 5628
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int a, b;
    cin >> a >> b;
    if (a == 1) {
        a = 14;
    }
    if (b == 1) {
        b = 14;
    }
    if (a > b) {
        cout << "Alice" << endl;
    } else if (a < b) {
        cout << "Bob" << endl;
    } else {
        cout << "Draw" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int INF = 1e9 + 10;

int main() {
    int n, m;
    cin >> n >> m;
    VI mask(m), a(m);
    REP(i,m){
        a[i] = in();
        int b = in();
        REP(j,b){
            int x = in() - 1;
            mask[i] |= (1 << x);
        }
    }
    VVI dp(m + 1, VI(1 << n, INF));
    dp[0][0] = 0;
    REP(i,m) REP(b,1<<n){
        if (dp[i][b] == INF) continue;
        chmin(dp[i+1][b], dp[i][b]);
        chmin(dp[i+1][b|mask[i]], dp[i][b] + a[i]);
    }
    int ans = dp[m][(1<<n)-1];
    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16384
s = list(input())
n = len(s)

zenhan = s[:int((n-1)/2)]
kouhan = s[int((n+3)/2)-1:]

def kaibun_check(str):
  l = len(str)
  ls = int(l//2)+1
  for i in range(ls-1):
    if str[i] == str[l-i-1]:
      continue
    else:
      return False
      break
  return True
    
if kaibun_check(s) and kaibun_check(zenhan) and kaibun_check(kouhan):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
//#define NDEBUG

#include <bits/stdc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pdd pair<double, double>
#define pll pair<ll, ll>
#define modadd(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modtimes(a, b) (((a % MOD) * (b % MOD)) % MOD)

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 1LL << 60;


int main(){
    StarBurstStream

    int n;
    cin >> n;
    cerr << (n - (int)(n / 2)) << " " << n << "\n";
    cout << fixed << setprecision(10) << (n - (int)(n / 2)) / (double)n << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    long long a[100];
    long long n;
    cin>>n;
    a[0]=2;
    a[1]=1;
    for(int i=1;i<=n;i++)
    {
        if(i==1)
        {}
        else
        {
            a[i]=a[i-1]+a[i-2];
        }
    }
    cout<<a[n]<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

Cnt = [0 for i in range(10**6 + 8)]
for i in A:
    if Cnt[i] != 0:
        Cnt[i] = 2
        continue
    else:
        pass
    for j in range(i, 10**6 + 8, i):
        Cnt[j] += 1

ans = 0
for i in A:
    if Cnt[i] == 1:
        ans += 1
    else:
        pass

print(ans)

Measured memory_bytes: 32296
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c; cin >> a >> b >> c;
	if (a + b + c >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
    int n, l;

    cin >> n >> l;

    vector<string> s(n);

    for (auto i = 0; i < n; i++) {
        cin >> s[i];
    }

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

    for (auto&& i : s) {
        cout << i;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;
const int mod = 1e9+7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(100005);

int main()
{
    int n, k;
    cin >> n >> k;
    // k: blue
    // n-k: red
    
    for(int i = 1; i < k+1; i++){
         mint res = comb(k-1, i-1);
         mint res2 = comb(n-k+1, i);
         cout << res*res2 << endl;
    }
    return 0;
}

Measured memory_bytes: 4652
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;

    int sum=0;

    vector<int>w(n);
    for (int i=0;i<n;i++) {
        cin >>w[i];
        sum+=w[i];
    }

    int min=10000;
    int wx=0;

    vector<int>suma(n);
    for (int i=0;i<n;i++) {
        suma[i]=wx+w[i];
        wx+=w[i];
    }

    for (int i=0;i<n;i++) {
        if(abs(suma[i]-(sum-suma[i]))<min){
            min=abs(suma[i]-(sum-suma[i]));
        }
    }
    cout <<min<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from scipy.sparse.csgraph import dijkstra
import numpy as np

"""
最小カット
"""

N = int(input())
start = 0
goal = N+1

A = [0] + [int(x) for x in input().split()]

INF = 10 ** 12
graph = np.zeros((N+2,N+2),dtype=np.int64)
for i,a in enumerate(A[1:],1):
    if a >= 0:
        graph[start,i] = a
    else:
        graph[i,goal] = -a
for i in range(1,N+1):
    for j in range(2*i,N+1,i):
        if A[i] < 0 and A[j] > 0:
            graph[j][i] = INF

def max_flow(graph):
    flow = 0
    while True:
        dist,pred = dijkstra(graph, indices = start, return_predecessors = True, unweighted = True)
        if dist[goal] == np.inf:
            return flow
        path = []
        v = goal
        while True:
            path.append((pred[v],v))
            v = pred[v]
            if v == start:
                break
        add_flow = min(graph[x][y] for x,y in path)
        for x,y in path:
            graph[x][y] -= add_flow
            graph[y][x] += add_flow
        flow += add_flow

answer = sum(x for x in A if x > 0) - max_flow(graph)
print(answer)

Measured memory_bytes: 17084
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;

struct Edge {
  int to, cost;
  Edge(int to, int cost): to(to), cost(cost) {}
};

int N, tot;
vector<vector<Edge>> G;
vector<vector<bool>> used;

struct Dijkstra {
  vector<int> d;
  vector<int> prev;

  Dijkstra(int s) {
    d.resize(N, INF);
    prev.resize(N, INF);
    used.resize(N, vector<bool>(N, false));

    d.at(s) = 0;

    priority_queue<P, vector<P>, greater<P>> q;
    q.push(make_pair(0, s)); // firstが始点からの距離、secondが頂点
    while (!q.empty()) {
      int cost = q.top().first;
      int v = q.top().second;
      q.pop();
      if (d.at(v) < cost) continue;

      for (Edge e : G.at(v)) {
        if (d.at(e.to) > d.at(v) + e.cost) {
          d.at(e.to) = d.at(v) + e.cost;
          q.push(make_pair(d.at(e.to), e.to));
          prev.at(e.to) = v;
        }
      }
    }
  }

  void checkPrev(int s) {
    rep(i, N) {
      if (prev.at(i) == INF || i == s) continue;
      if (!used.at(i).at(prev.at(i))) {
        tot++;
        used.at(i).at(prev.at(i)) = true;
        used.at(prev.at(i)).at(i) = true;
      }
    }
  }
};

int main() {
  int M;
  cin >> N >> M;
  G.resize(N);

  rep(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;

    G.at(a).emplace_back(b, c);
    G.at(b).emplace_back(a, c);
  }

  rep(i, N) {
    Dijkstra di(i);
    di.checkPrev(i);
  }
  cout << M - tot << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  ll cu=0;
  vll a(n);
  ll f=MOD;
  rep(i,n) {
    cin>>a[i];
    if(a[i]%10!=0){
      f=min(a[i],f);
    }
    cu+=a[i];
  }
  if(cu%10!=0){
    COUT(cu);
  }
  else{
    if(f==MOD){
      COUT(0);
    }
    else{
      COUT(cu-f);
    }
  }
}
  


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    string s, t;
    cin >> n >> s >> t;

    ll p, si;
    rep(i, n){
        p = 0;
        si = i;
        while(s[si]==t[p] && si < n)si++, p++;
        if(si == n)break;
    }
    cout << 2*n-p << endl;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

void solve(int test) {

	int n ; cin >> n ;
	int a[n]; rep(i,0,n) cin >> a[i] ;
	int ans = 0 ;
	for(int i = 1 ;i < n ; ++i ) {
		if(a[i] < a[i-1]) ans += a[i-1] - a[i], a[i] = a[i-1] ; 
	}	
	cout << ans ; 
}
 
int32_t main() {
 

    fast;
	int t=1;
	// cin>>t;
	rep(i,1,t+1) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
#define N 9
void reads(string& x) {char kk[N]; scanf("%s", kk); x = kk;}

int n;
string s;
vector<pair<string, int>> v;

int main () {
    scanf("%d", &n);
    v.push_back(pair<string, int>("AC", 0));
    v.push_back(pair<string, int>("WA", 0));
    v.push_back(pair<string, int>("TLE", 0));
    v.push_back(pair<string, int>("RE", 0));
    for (int i = 0; i < n; i++) {
        reads(s);
        for (int j = 0; j < 4; j++) {
            if (s == v[j].first) v[j].second++;
        }
    }
    for (auto x : v) {
        printf("%s x %d\n", x.first.c_str(), x.second);
    }

    return 0;
}

Measured memory_bytes: 3780
import java.util.Scanner


object Main {
  val sc = new Scanner(System.in)

  def main(args: Array[String]): Unit = {
    val n = sc.nextInt
    val m = sc.nextInt

    val c = sc.nextInt

    val b = List.fill(m){
      sc.nextInt
    }

    val a = List.fill(n){
      List.fill(m){
        sc.nextInt
      }
    }

    def culc(target: List[Int]): Boolean ={
      (target zip b).map{case (x,y) => x * y}.sum + c > 0
    }

    //    val res = a.filter(culc(_)).size
    val res = a.count(culc)

    println(res)
  }


}

Measured memory_bytes: 25924
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<int>;


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

	cout << min(N*A, B) << endl;

	return 0;
}

Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;
const MOD: i32 = 1000000007;
// const MOD: i32 = 998244353;

fn main() {
    let x: isize = read!();
    let ans = if x>=30 {"Yes"}else{ "No"};
    println!("{}", ans);
}

Measured memory_bytes: 2088
N,M = map(int,input().split())
xs = list(map(int,input().split()))
ys = list(map(int,input().split()))
MOD = 10**9+7

total_w = total_h = 0
for n in range(1,N):
    w = xs[n] - xs[n-1]
    w = (w * n * (N-n)) % MOD
    total_w = (total_w + w) % MOD
for n in range(1,M):
    h = ys[n] - ys[n-1]
    h = (h * n * (M-n)) % MOD
    total_h = (total_h + h) % MOD
ans = (total_w * total_h) % MOD
print(ans)


Measured memory_bytes: 18624