akhauriyash/Code-Regression huggingface dataset:
// AOJ 2413: Tree Planting
// 2017.12.8 bal4u@uu

#include <stdio.h>

char m[1001][2005];
char sr[1001], sc[1001];

int main()
{
	int h, w, r, c;
	char buf[12], *p;

	fgets(buf, 12, stdin);
	sscanf(buf, "%d%d", &h, &w);
	for (r = 0; r < h; r++) {
		fgets(p=m[r], 2005, stdin);
		for (c = 0; c < w; c++, p+=2) {
			if (!(*p & 1)) sr[c] = !sr[c], sc[r] = !sc[r];
		}
	}
	for (r = 0; r < h; r++) {
		for (p = m[r], c = 0; c < w; c++, p+=2) {
			if (!(sc[r]^sr[c])) *p = '1' - (*p & 1);
		}
		*(p-1) = 0;
		puts(m[r]);
	}
	return 0;
}

Measured memory_bytes: 3756
N = int(input())
H = list(map(int, input().split()))

No = 0

tmp = H[0]-1
for i in range(1,N):
  if tmp < H[i]:
    tmp = H[i]-1
  elif tmp == H[i]:
    tmp = H[i]
  else:
    No = 1
    break

print("Yes" if No == 0 else "No")

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

int main() {

	int W[10];
	int K[10];

	int i = 0;
	while (i<10) {
		cin >> W[i];
		i++;
	}

	while (i<20) {
		cin >> K[i-10];
		i++;
	}

	sort(W,W+10);
	sort(K,K+10);

	cout << W[7] + W[8] + W[9] << " " << K[7] + K[8] + K[9] << endl;

	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;
int main(){
    int S,W;
    cin>>S>>W;
    if(W>=S){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 2147483647
typedef long long ll;
using namespace std;
#define N (1<<17)
class RUQ{
private:
    int dat[2*N];
    vector<int> hs;
    void dfs(int l,int r,int a,int b,int k,int x){
	if(l<=a&&b<=r){dat[k]=x;return;}
	if(b<=l||r<=a)return;
	int m=(a+b)/2;
	dfs(l,r,a,m,k*2+1,x);
	dfs(l,r,m,b,k*2+2,x);
    }
public:
    void Init(){
	hs.push_back(mod);
	lol(i,2*N)dat[i]=0;
    }
    void Update(int l,int r,int x){
	dfs(l,r+1,0,N,0,hs.size());
	hs.push_back(x);
    }
    int Query(int i){
	i+=N-1;
	int maxi=dat[i];
	while(i){
	    i=(i-1)/2;
	    maxi=max(maxi,dat[i]);
	}
	return hs[maxi];
    }
};
int main(){
    int n,q;cin>>n>>q;
    RUQ ruq;ruq.Init();
    while(q--){
	int c;cin>>c;
	if(c==0){
	    int a,b,x;cin>>a>>b>>x;
	    ruq.Update(a,b,x);
	}
	if(c==1){
	    int x;cin>>x;
	    cout<<ruq.Query(x)<<endl;
	}
    }
    return 0;
}



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

int main()
{
  int n;
  cin>>n;
  vector<int> a(n),b(n),c(n-1);
  for(int &i:a) cin>>i;
  for(int &i:b) cin>>i;
  for(int &i:c) cin>>i;
  int ans=0;
  for(int i=0;i<n-1;i++)
  {
    if(a[i+1]-a[i]==1)
      ans+=c[a[i]-1];
    ans+=b[a[i]-1];
  }
  ans+=b[a.back()-1];
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	
	int n, m;
	cin >> n >> m;
	
	int ans = 0;
	rep(i, n){
		int sum = 0;
		int tmp;
		rep(j, m) {cin >> tmp; sum += tmp;}
		ans = max(ans, sum);
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3096
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    X, Y = next(it), next(it)

    for a in range(101):
        b = X - a
        if b < 0:
            continue
        if 2*a + 4*b == Y:
            print("Yes")
            return
    print("No")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 61836
using System;
class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int K = int.Parse(Console.ReadLine());
            int X = int.Parse(Console.ReadLine());
            int Y = int.Parse(Console.ReadLine());

            int fee = 0;

            for(int i = 1; i <= N; i++)
            {
                if(i <= K)
                {
                    fee += X;
                }
                else
                {
                    fee += Y;
                }
            }

            Console.WriteLine(fee);
        }
    }

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
int main(void)
{
  int a[3];
  std::cin >> a[0] >> a[1] >> a[2];
  std::sort(a, a + 3);
  std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl;
}

Measured memory_bytes: 1184
n1, n2 = [int(i) for i in input().split()]

n3 = [int(j) for j in input().split()]

n3.sort(reverse=True)

n4 = 0
for i1 in range(n1):
    if i1 >= n2:
        n4 += n3[i1]
print(n4)

Measured memory_bytes: 31596
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int n,m,h[114514],ma[114514];
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        cin>>h[i];
        ma[i]=0;
        } 
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        ma[a]=max(ma[a],h[b]);
        ma[b]=max(ma[b],h[a]);
        }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=h[i]>ma[i];
        }
    cout<<ans<<endl;
}

Measured memory_bytes: 4444
a, b, k = map(int, input().split())


def gcd(a, b):
    return gcd(b, a % b) if b != 0 else a


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors


print(make_divisors(gcd(a, b))[k-1])


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second

typedef long long LL;

int n;
map <int , int > a;
int b[123456];

int main() {
  //  freopen("test.txt","r",stdin);
    cin >> n;
    for (int i =1 ; i <= n ; i++) {
        cin >> b[i];
        a[i] = b[i];
    }
    int now = 1;
    int ans = 0;
    int c,d;
    while ( 1) {
        c = a[a[now]];
        now = a[now];
        ans++;
        if ( now == 2 ) {
            cout << ans;
            return 0;
        }
        if ( ans > n ) {
            cout << -1;
            return 0;
        }
    }
}


Measured memory_bytes: 5376
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int num[n];
    num[0]=0;
    for(int i=1;i<n;i++){
        if(s[i] == 'W') num[0]++;
    }
    int mx=num[0];
    for(int i=0;i<n-1;i++){
        if(s[i] == 'E' && s[i+1] == 'E') num[i+1] = num[i]+1;
        else if(s[i] == 'W' && s[i+1] == 'W') num[i+1] = num[i]-1;
        else num[i+1] = num[i];
        mx = max(mx,num[i+1]);
    }
    cout << n-1-mx << endl;
}

Measured memory_bytes: 1796
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    cins(s);

    if(s.size()%2==0) {
        bool ans=true;
        for(int i=0; i<s.size()/2; i++)
            if(s[i]!=s[s.size()/2+i])
                ans=false;

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep_r(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define resize(x, n) x.resize(n)
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ll MAX = 100000;
struct edge {
    ll from, to, weight;
    edge(ll f, ll t, ll w) : from(f), to(t), weight(w) { }
};
vector<vector<edge>> edges;
vector<vector<ll>> graph;
vector<bool> visited;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll n, k;

ll dp[2001][2001];

ll c(ll n, ll r) {
    if (n < r) return 0;
    if (dp[n][r] != -1) return dp[n][r];
    if (n == r || r == 0) return 1;
    if (r == 1) return dp[n][r] = n;
    return dp[n][r] = (c(n-1, r-1) + c(n-1, r)) % mod;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    memset(dp, -1, sizeof(dp));
    cin >> n;
    cin >> k;
    ll blue = k, red = n-k;
    for (ll i = 1; i <= k; i++) {
        ll answer = c(n-k+1, i) * c(k-1, i-1) % mod;
        // printf("%lld回の場合 %lld\n", i, answer);
        cout << answer << "\n";
    }
}

Measured memory_bytes: 34964
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll i,cnt,ta,tb;
    for(i=0;i<n;i++){
      cin>>ta >>tb;
      if(ta>=a && tb>=b)cnt++;
    }
    cout <<cnt;
    return 0;
}


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

import copy

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
B = copy.deepcopy(A)

for i in range(N):
    for j in range(N):
        for k in range(N):
            B[j][k] = min(B[j][k], B[j][i]+B[i][k])

INF = int(1E17)
ok = True
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if A[i][j] != B[i][j]:
            ok = False
        d = INF
        for k in range(N):
            if k == i or k == j:
                continue
            d = min(d, A[i][k] + A[k][j])
        if d > A[i][j]:
            ans += A[i][j]
                
if not ok:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 58588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)

int main(){
    int n; sc(n);
    int ans = 0, left, right;
    string s, tl, tr;
    vector<vector<int> > V(10, vector<int>(10, 0));
    rep(i, 1, n+1){
        s = to_string(i);
        tl = s[0], tr = *(s.end()-1);
        left = atoi(tl.c_str());
        right = atoi(tr.c_str());
        V[left][right] += 1;
    }
    rep(i, 0, 10){
        rep(j, 0, 10) ans += V[i][j] * V[j][i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */
 
int main(){
    string s; cin >> s;
    if (s == "AAA" || s == "BBB") {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    
}


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

int main() {
	int N,gate[101], M, X,a,cost_A,cost_B;
	cin >> N >> M >> X;
	for (int i = 0; i < N; i++) {
		gate[i] = 0;
	}
	for (int i = 0; i < M; i++) {
		cin >> a;
		gate[a] = 1;
	}
	for (int i = 0; i < X; i++) {
		if (gate[i] == 1) {
			cost_A++;
		}
	}
	for (int i = X; i < N; i++) {
		if (gate[i] == 1) {
			cost_B++;
		}
	}

	if (cost_A > cost_B) {
		cout << cost_B << endl;
	}
	else {
		cout << cost_A << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int A, B, C;
    cin >> A >> B >> C;
    map<int, int> N;
    N[A]++;
    N[B]++;
    N[C]++;
    if(N[5]==2 and N[7]==1) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

int main() {
    string s;
    int d;
    cin>>s>>d;
    // dp[i][0] - #integers with sum_digits p*d + i using curr digit m as [0..9]
    // dp[i][1] - #integers with sum_digits p*d + i using curr digit m as [0..m]
    vector<vector<int>> prev(d, vector<int> (2, 0));
    prev[0][0] = prev[0][1] = 1;
    for(int i = s.size()-1; i>=0; i--) {
        vector<vector<int>> curr(d, vector<int> (2, 0));
        int m = (int) (s[i] - '0');
        for(int j=0; j<d; j++) {
            for(int k=0; k<10; k++) {
                curr[(j+k)%d][0] = (curr[(j+k)%d][0] + prev[j][0]) % mod;
                if(k < m) curr[(j+k)%d][1] = (curr[(j+k)%d][1] + prev[j][0]) % mod;
            }
            curr[(j+m)%d][1] = (curr[(j+m)%d][1] + prev[j][1]) % mod;
        }
        prev = curr;
    }
    cout<<(prev[0][1] - 1 + mod) % mod<<endl;
    return 0;
}


Measured memory_bytes: 256
S = list(input())
import re
S.reverse()
D1 = "maerd"
D2 = "remaerd"
E1 = "esare"
E2 = "resare"
S = "".join(S)
S = re.split('maerd|remaerd|esare|resare', S)
if len(S) == S.count("") :
  print("YES")
else:
  print("NO")

Measured memory_bytes: 10344
import sys
from io import StringIO
import unittest

def resolve():
    inp = input().split()
    a = int(inp[0])
    b = int(inp[1])
    k = int(inp[2])

    if (a - k) <= 0 :
        k = k - a
        a = 0
    else:
        a = a - k
        k = 0

    if (b - k) <= 0:
        k = k - b
        b = 0
    else:
        b = b - k
        k = 0

    print(str(a) + ' ' + str(b))

if __name__ == "__main__":
    resolve()

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n, ans = 0; cin >> n;
    double sum = 0, x[n], y[n]; REPI(i, n) cin >> x[i] >> y[i];

    REPI(i, n)
        for(int j = i; j < n; j++){
            double x_point = x[i] - x[j];
            double x = sqrt(pow(x_point, 2) + pow(y[i] - y[j], 2));
            //cout << x << endl;
	    if(j != i) sum += x;
        }
    printf("%.7lf", sum / ((double)(n) * 0.5));
}


    


Measured memory_bytes: 384
function Main(input) {
	if (input[0] === input[1]) console.log('Bad')
	else if (input[1] === input[2]) console.log('Bad')
	else if (input[2] === input[3]) console.log('Bad')
	else console.log('Good')
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d={}
for i in a:
  if i in d:
    d[i][0]+=1
  else:
    d[i]=[1,0]
for i in b:
  if i in d:
    d[i][0]+=1
    d[i][1]+=1
  else:
    d[i]=[1,1]
l=[]
for i in d:
  l.append([d[i][0],i,d[i][1]])
l.sort()
l.reverse()


if l[0][0]>n:
  print("No")
else:
  print("Yes")
  l.append(l[0])
  cc=0
  ansa=[]
  i=1
  while l[i][2]==0:
    i+=1
  j=i+1
  while j!=len(l) and l[j][2]==0:
    j+=1
  ic,jc=0,0
  for t in a:
    if t==l[0][1]:
      continue
    cc+=1
    if cc>n-l[0][0]:
      ansa.append(l[0][1])
    elif l[i][1]==t:
      ansa.append(l[j][1])
      jc+=1
      if jc==l[j][2]:
        j+=1
        while j!=len(l) and l[j][2]==0:
          j+=1
        jc=0
    else:
      ansa.append(l[i][1])
      ic+=1
      if ic==l[i][2]:
        i=j
        j+=1
        while j!=len(l) and l[j][2]==0:
          j+=1
        ic=jc
        jc=0
  ans=[]
  ii=0
  for t in a:
    if t==l[0][1]:
      ans.append(l[i][1])
      ic+=1
      if ic==l[i][2]:
        i=j
        j+=1
        while j!=len(l) and l[j][2]==0:
          j+=1
        ic=jc
        jc=0
    else:
      ans.append(ansa[ii])
      ii+=1
  print(" ".join(map(str,ans)))
  
        

Measured memory_bytes: 171172
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N, K;
  cin >> N >> K;

  int ret = 0;
  ll p = 1;
  while(N >= p){
    p*=K;
    ret++;
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var ans = "";
            for(int i  =0; i < s.Length; i++)
            {
                ans += (char)((s[i] + n - 65) % 26 + 65);
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 46164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  int x,y,z,k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x),b(y),c(z);
  rep(i,x) cin >> a.at(i);
  rep(i,y) cin >> b.at(i);
  rep(i,z) cin >> c.at(i);
  vector<ll> ab;
  rep(i,x)rep(j,y) ab.push_back(a.at(i)+b.at(j));
  sort(ab.begin(),ab.end(),greater<ll>());
  vector<ll> abc;
  rep(i,min(k,x*y))rep(j,z) abc.push_back(ab.at(i)+c.at(j));
  sort(abc.begin(),abc.end(),greater<ll>());
  rep(i,k) cout << abc.at(i) << endl;
  
  return 0;
}



Measured memory_bytes: 43240
n,k=map(int,input().split())
d=list(map(str,input().split()))
flg=False
while True:
    nn=str(n)
    flg=True
    for i in range(len(nn)):
        if nn[i] in d:
            flg=False
    if flg:
        print(n)
        exit()
    else:
        n+=1

Measured memory_bytes: 73112
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	//参加人数
		int n = sc.nextInt();
      	//初期の持ち点
      	int k = sc.nextInt();
      	//回数
      	int q = sc.nextInt();
		// n人それぞれの最初の持ち点を格納する
      	int[] point = new int[n];
        for(int i=0;i<point.length;++i){
            point[i] = k;
        }
      	//ゲーム
      	while(sc.hasNext()){
           //正解者
          int a = sc.nextInt();
          int w = a-1;
          //正解者に１足す
          point[w]+=1;
        }
          //全員に１引く
          for(int i=0;i<point.length;++i){
             point[i] -= q;
          //勝敗判断
         	if(point[i]> 0){
            	System.out.println("Yes");
          	}else{
            	System.out.println("No");           
          	}
          }
    }
}

Measured memory_bytes: 62264
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):
    ans += b[a[i]-1]
    if i > 0 and a[i] == a[i-1] + 1:
        ans += c[a[i-1]-1]

print(ans)


Measured memory_bytes: 38384
#include <stdio.h>

void trace(int A[], int N){
  int i;
  for(i=0; i<N; i++)
    {  
    if(i>0)
      printf(" ");
    printf("%d",A[i]);   
  }
  printf("\n");
}

void insertionSort(int A[], int N){
  int j, i, v;
  for(i=1; i<N; i++)
    {
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v)
      {
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
  trace(A, N);
  }
}

int main(){
  int N, i, j;
  int A[100];
  
  scanf("%d", &N);
  for(i=0;i<N; i++)
    scanf("%d", &A[i]);
  
  trace(A,N);
  insertionSort(A,N);
  
  return 0;
}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N, L; cin >> N >> L;
    vec a(N); readv(a);
    int i0 = -1;
    REP(i, N - 1) if(a[i] + a[i + 1] >= L){
        i0 = i;
        break;
    }
    if(i0 == -1) cout << "Impossible" << endl;
    else{
        cout << "Possible" << endl;
        REP(i, i0) cout << i + 1 << endl;
        IFOR(i, i0, N - 1) cout << i + 1 << endl;
    }
    
    return 0;
}

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

signed main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<' '<<b<<' '<< c<<endl;

	return 0;
}


Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input!(n: usize, m: usize, a: [usize1; n]);
    let mut start = vec![vec![]; m];
    let mut end = vec![vec![]; m];
    for i in 0..(n - 1) {
        let from = a[i];
        let to = a[i + 1];
        start[from].push(to);
        end[to].push(from);
    }

    let mut total = 0;
    let mut count = 0;
    for from in 0..m {
        for &to in start[from].iter() {
            if from > to {
                count += 1;
                total += to + 1;
            } else {
                total += to - from;
            }
        }
    }
    let mut ans = total;
    for cur in 1..m {
        for &from in end[cur - 1].iter() {
            count -= 1;
            let to = cur - 1;
            total += (to + m - from) % m;
            total -= 1;
        }
        total -= count;

        ans = cmp::min(ans, total);
        count += start[cur - 1].len();
    }
    println!("{}", ans);
}


Measured memory_bytes: 18684
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,c,d,e,f,g,h,n1,n2,n3,n4;
	cin>>a>>b>>c>>d>>e>>f>>g>>h;
	if(a==1) n1=b*6000;
	else if(a==2) n1=b*4000;
	else if(a==3) n1=b*3000;
	else n1=b*2000;
	
	if(c==1) n2=d*6000;
	else if(c==2) n2=d*4000;
	else if(c==3) n2=d*3000;
	else n2=d*2000;
	
	if(e==1) n3=f*6000;
	else if(e==2) n3=f*4000;
	else if(e==3) n3=f*3000;
	else n3=f*2000;
	
	if(g==1) n4=h*6000;
	else if(g==2) n4=h*4000;
	else if(g==3) n4=h*3000;
	else n4=h*2000;
	
	cout<<n1<<endl;
	cout<<n2<<endl;
	cout<<n3<<endl;
	cout<<n4<<endl;
	
	return 0;
}



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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
ll koubaisu(ll a,ll b){
  ll x=a*b;
  /* 自然数 a > b を確認・入替 */ 
  if(a<b){ 
    ll tmp=a; 
    a=b; 
    b=tmp; 
  }
  /* ユークリッドの互除法 */ 
  ll r=a%b; 
  while(r!=0){ 
    a=b; 
    b=r; 
    r=a%b; 
  }
 
  /* 最小公倍数を出力 */ 
  return x/b; 
}
ll gcd(ll a,ll b){
    ll r=a%b; 
    while(r!=0){ 
      a=b; 
      b=r; 
      r=a%b; 
    }
    return b;
}
int main(){
  ll n,m;cin>>n>>m;
  string s,t;cin>>s>>t;
  ll num=koubaisu(n,m);
    ll num2=gcd(n,m);
    ll n2=n/num2;
    ll m2=m/num2;
    ll nn=0,mm=0;
    bool flag=true;
    while(1){
      // cout<<nn<<" "<<mm<<endl;
      if(nn>=s.size()||mm>=t.size())break;
      if(s[nn]!=t[mm])flag=false;
      nn+=n2;
      mm+=m2;
    }
    if((s[0]!=t[0]))flag=false;
    if(flag)cout<<num<<endl;
    else cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define endl '\n'
#define eb emplace_back
#define MAX (int)1e5 + 5
#define vi vector<int>
#define pii pair<int,int>
#define ok cerr<<"ok"<<endl
#define bb binary_search
#define all(A) A.begin(),A.end()
#define mp make_pair
#define pb push_back
#define inf INT_MAX/2
#define fi first
#define se second
//#define int  long long 
using namespace std;



int32_t main() {
	string s;
	cin >> s;
	int sum = 0;
	for(int i = 0; i<(int)s.size(); i++){
		sum += s[i] - '0';
	}
	
	if(sum%9 == 0){
		puts("Yes");
	}else{
		puts("No");
	}
	return 0;
} 

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

long long n,m,sumv=0;
long long mon[200005];

long long cmp(long long a,long long b)
{
	return a<b;
}

int main()
{
	cin>>n>>m;
	for (long long i=1;i<=n;i++)  cin>>mon[i];
	if (n<=m)
	{
		cout<<0<<endl;
		return 0;
	}
	sort(mon+1,mon+n+1,cmp);
	for (long long i=1;i<=n-m;i++)  sumv+=mon[i];
	cout<<sumv<<endl;
	return 0;
}

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

def dfs():
    for i in range(n):
        if  a[i]%2 ==0:
            if a[i]%3 != 0 and a[i]%5 != 0:
                return False
                    
            

if dfs() != False:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()



int main()
{
  int a, b;
  cin >> a >> b;
  int act = 1, ans = 0;
  while(act < b)
    act += a - 1, ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin>>n;
  for(int i=0; i<=25; i++){
    for(int j=0; j<=14; j++){
      if(4*i+7*j==n){
        cout<<"Yes";
        return 0;
      }
    }
  }
  cout<<"No";
}

Measured memory_bytes: 3608
#include<stdio.h>
#define MAX 100001
 
int parent(int);
int left(int);
int right(int);
 
int main(){

  int A[MAX];
  int h, i; 
 
  scanf("%d",&h);
 
  for(i=1;i<=h;i++){

    scanf("%d",&A[i]);

  }
 
  for(i = 1; i <= h; i++){

    printf("node %d: key = %d, ", i, A[i]);

    if(parent(i) >= 1){

      printf("parent key = %d, ", A[parent(i)]);

    }

    if(left(i) <= h){

      printf("left key = %d, ",A[left(i)]);
 
    }

    if(right(i) <= h){

      printf("right key = %d, ", A[right(i)]);

    }

    printf("\n");
  }

  return 0;
}
 
int parent(int x){

  return (x / 2);

}
 
int left(int x){

  return (2 * x);

}
 
int right(int x){
  
  return (2 * x + 1);

}

Measured memory_bytes: 608
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from functools import lru_cache
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#main

n=int(input())
H=list(map(int,input().split()))
dp=[inf]*n
for a in range(n):
    if a==0:
        dp[a]=0
    elif a==1:
        dp[a]=abs(H[a]-H[a-1])
    else:
        dp[a]=min(dp[a-2]+abs(H[a]-H[a-2]),dp[a-1]+abs(H[a]-H[a-1]))
print(dp[n-1])

Measured memory_bytes: 16764
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

int H, W, K;
vvi a;

bool fall() {
    bool updated = false;
    rep(j, W) {
        queue<int> holl;
        rrep(i, H) {
            if (!holl.empty() && a[i][j] != 0) {
                int h = holl.front(); holl.pop();
                a[h][j] = a[i][j];
                a[i][j] = 0;
                updated = true;
            }
            if (a[i][j] == 0) {
                holl.push(i);
            }
        }
    }

    return updated;
}

int puyo() {
    int t = 0;
    rep(i, H) {
        rep(j, W) {
            if (a[i][j] == 0) continue;
            int k;
            for (k = j; k < W && a[i][k] == a[i][j]; k++) {
                ;
            }
            if (k - j >= K) {
                rep2(l, j, k) {
                    t += a[i][l];
                    a[i][l] = 0;
                }
            }
            j = k - 1;
        }
    }
    return t;
}

int solve() {
    int score = 0;
    for (int t = 1; fall(); t <<= 1) {
        score += t * puyo();
    }
    return score;
}

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

    cin >> H >> W >> K;
    a.resize(H, vi(W));
    rep(i, H) {
        string s;
        cin >> s;
        rep(j, W) {
            a[i][j] = s[j] - '0';
        }
    }

    int ans = 0;
    vvi b = a;
    rep(i, H) {
        rep(j, W) {
            a[i][j] = 0;
            ans = max(ans, solve());
            a = b;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
MOD = 10**9+7
s = input()
n = len(s)

dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1
b = 1
for i in range(1,n+1):
    if s[n-i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i][(j*b+k)%13] += dp[i-1][k]
    else:
        j = int(s[n-i])
        for k in range(13):
            dp[i][(j*b+k)%13] += dp[i-1][k]
    for k in range(13):
        dp[i][k] %= MOD
    b *= 10
    b %= 13

print(dp[n][5]%MOD)

Measured memory_bytes: 61916
fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val input = readLine()!!.split(" ")

    val line = mutableListOf<Int>()

    for(i in 0..n-1){
        line.add(input[i].toInt())
    }

    val ans = mutableListOf<Int>()

    for(i in 0..n-1){
        var big = 0
        var small = 0
        for(j in 0..n-1){
            if(i < j){
                big += line[j]
            }
            else{
                small += line[j]
            }
        }
        ans.add(Math.abs(big - small))
    }
    ans.sort()

    //println(ans)
    println(ans[0])
}

Measured memory_bytes: 37988
from itertools import permutations
from functools import reduce

n = int(input())

rn = int(n **.5) + 1

ptn = permutations([i for i in range(1, rn + 1)], 3)

ans = [0] * (n + 1)
for i in range(1, rn + 1):
  for j in range(1, rn + 1):
    for k in range(1, rn + 1):
      idx = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if idx <= n: 
        ans[i**2 + j**2 + k**2 + i*j + j*k + k*i] += 1

for an in ans[1:]:
  print(an)

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

int main()
{
int N;scanf("%d",&N);
double low=N*0.92592592592;double high=(N+1)*0.92592592592;
int ans=low;
if(ans<low&&ans+1>=high){printf(":(\n");}
else if(ans+1<high)printf("%d",ans+1);
else printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc139_d.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll N;
  cin >> N;
  cout << ((N - 1) * N) / 2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int D = scan.nextInt();
        int X = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int answer = 0;
        for (int i = 0; i < N; i++) {
            answer += (D-1)/A[i]+1;
        }
        answer += X;
        System.out.println(answer);
    }
}

Measured memory_bytes: 25044
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to) 
int c[26];
bool ch(int x) {
	int a = 26, b = x;
	if(b < a) swap(a, b);
	while(a) {
		int t = b / a;
		swap(b -= t * a, a);
	}
	if(b != 1) return false;
	else {
		rep(i,26) {
			c[i] = (x * i) % 26;
		}
		return true;
	}
}
int main() {
	int n;
	char str[260];
	scanf("%d\n", &n);
	while(n--) {
		gets(str);
		string s = str;
		int len = s.length();
		bool f = 0;
		rep2(i,1,10000) {
			if(ch(i)) {
				rep(k,26) {
					char ns[260];
					rep(j,len) {
						if(islower(str[j])) {
							int b = str[j] - 'a';
							ns[j] = (char) ((c[b] + k) % 26 + 'a');
						} else {
							ns[j] = str[j];
						}
					}
					rep(j,len) {
						if(ns[j] == 't' && ns[j+1] == 'h' && ns[j+2] == 'a' && ns[j+3] == 't' ||
							ns[j] == 't' && ns[j+1] == 'h' && ns[j+2] == 'i' && ns[j+3] == 's') {
							f = 1;
							break;
						}
					}
					if(f) {
						rep(j,len) {
							cout << ns[j];
						}
						cout << endl;
						break;
					}
				}
			}
			if(f) break;
		}
	}
	return 0;
}

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

int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    vector<int> divisor;
    for (int i = 1; i <= min(a, b); i++) {
        if (a % i == 0 && b % i == 0) {
            divisor.push_back(i);
        }
    }
    cout << divisor[divisor.size() - k] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

struct UnionFind{
  vi p;
  void init(int n){
    p.resize(n);
    FOR(i, 0, n) p[i] = -1;
  }
  int find(int a){
    if(p[a] < 0) return a;
    p[a] = find(p[a]);
    return p[a];
  }
  bool merge(int a, int b){
    a = find(a);
    b = find(b);
    if(a == b) return false;
    if(a > b) swap(a, b);
    p[a] += p[b];
    p[b] = a;
    return true;
  }
};
UnionFind uf;
int n, m;
vpii v;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    v.pb(mp(a, b));
  }
  int ans = 0;
  FOR(i, 0, m){
    uf.init(n);
    FOR(j, 0, m){
      if(i == j) continue;
      uf.merge(v[j].fi, v[j].se);
    }
    FOR(j, 0, n)if(uf.find(j) != 0){
      ans++;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[301][301],g[301][301];
int main(){
	int n,m,l;
	cin>>n>>m>>l;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
		{
			f[i][j]=1010100010;
		}
	}
	
	for(int i=1;i<=m;++i)
	{
		int yy,uu,ii;
		cin>>yy>>uu>>ii;
		f[yy][uu]=f[uu][yy]=ii;
	}
	for(int i=1;i<=n;++i)
	{
		f[i][i]=0;
	}
	for(int k=1;k<=n;++k)
	{
		for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=n;++j)
			{
				f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
			}
		}
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
		{
			if(f[i][j]<=l) g[i][j]=g[j][i]=1;
			else
			{
				g[i][j]=12345678;
			}
		}
	}
	for(int i=1;i<=n;++i)
	{
		g[i][i]=1;
	}
	for(int k=1;k<=n;++k)
	{
		for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=n;++j)
			{
				g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
			}
		}
	}
	
	int T;
	cin>>T;
	while(T--)
	{
		int qq,ww;
		cin>>qq>>ww;
		if(g[qq][ww]>10000000) cout<<-1;
		else cout<<g[qq][ww]-1;
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
from itertools import combinations
import numpy as np


def main():
    n, m, x = list(map(int, input().split()))
    A = np.array([list(map(int, input().split())) for _ in range(n)])
    cost = []
    for i in range(n):
        combs = combinations(range(n), i+1)
        for comb in combs:
            A2 = np.array([A[c] for c in comb])
            A2sum = np.sum(A2, axis=0)
            if (A2sum[1:] >= x).all():
                cost.append(A2sum[0])

    if len(cost) == 0:
        print(-1)
    else:
        print(min(cost))




if __name__ == '__main__':
    main()


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

int main() {
  long n,k,ans;
  string s;
  vector<long> a;
  cin >> n >> k >> s;
  
  if(s[0]=='0') a.push_back(0);
  a.push_back(1);
  for(long i=1;i<n;i++) {
    if(s[i-1]==s[i]) a[a.size()-1]++;
    else a.push_back(1);
  }
  if(s[n-1]=='0') a.push_back(0);

  if(a.size()<=k*2+1) {
    ans=n;
  } else {
    long x=0;
    for(long i=0;i<k*2+1;i++) x+=a[i];
    ans=x;
    for(long i=0;i<(a.size()-k*2+1)/2;i++) {
      x-=a[i*2]+a[i*2+1];
      x+=a[k*2+i*2+1]+a[k*2+i*2+2];
      ans=max(ans,x);
    }
  }
  cout << ans << endl;
}

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

int main(void){
    int n,h;
    cin >> n >> h;
    vector<int> monster(n);
    for(int i=0;i<n;i++) cin >> monster[i];
    sort(monster.begin(),monster.end());
    reverse(monster.begin(),monster.end());

    ll sum = 0;
    for(int i=h;i<n;i++) sum += monster[i];
    cout << sum << endl;
}

Measured memory_bytes: 1024
a = gets.to_i # 500
b = gets.to_i # 100
c = gets.to_i # 50
x = gets.to_i
ways = 0

(a + 1).times do |i|
  (b + 1).times do |j|
    (c + 1).times do |k|
      sum = 500*i + 100*j + 50*k
      if sum == x
        ways += 1
      end
    end
  end
end

puts ways

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

using namespace std;

#define MAX 1000000007

int main()
{
	int min;
	int A, B;
	cin >> A >> B;
	long long int ans = 1;
	int n = A - B;
	if (n == 0 || n == -1 || n == 1) {
		for (int i = 1; i <= A; i++) {
			ans *= i;
			ans %= MAX;
		}
		for (int i = 1; i <= B; i++) {
			ans *= i;
			ans %= MAX;
		}
		if (A == B) {
			ans *= 2;
			ans %= MAX;
		}
	}
	else {
		ans = 0;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define x first
#define y second

template<typename T>inline void read(T &x)
{
	char c=x=0;
	for(c=getchar();!isdigit(c);c=getchar());
	for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
}

namespace gg
{
	template<typename T>inline bool check_max(T a,T &b){return a>b?b=a,1:0;}
	template<typename T>inline bool check_min(T a,T &b){return a<b?b=a,1:0;}
	typedef long long ll;
	typedef std::pair<int,int> pii;
	
	inline void insert(int a,pii &b){check_max(a,b.y);if(b.y>b.x)std::swap(b.x,b.y);}

	const int N=201000,M=N*2;
	int begin[N],next[M],to[M];
	int fa[N],dep[N],cnt[N];
	bool ex[N];
	int n,e;

	void add(int x,int y,bool k=1)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		if(k)add(y,x,0);
	}
	pii f[N];
	int df[N];
	void dfs0(int p,int h=0)
	{
		fa[p]=h;
		f[p]=pii(0,0);
		cnt[p]=ex[p];
		dep[p]=0;

		for(int i=begin[p],q;i;i=next[i])
			if((q=to[i])!=h)
			{
				dfs0(q,p);
				insert(f[q].x+1,f[p]);
				check_max(dep[q]+1,dep[p]);
				cnt[p]+=cnt[q];
			}
	}
	void dfs1(int p,int dis=0)
	{
		insert(dis,f[p]);
		df[p]=n+1;
		
		for(int i=begin[p],q;i;i=next[i])
			if((q=to[i])!=fa[p])
			{
				if(cnt[q])check_min(dep[q]+1,df[p]);

				int x=std::max(dis,(f[q].x+1==f[p].x?f[p].y:f[p].x))+1;
				dfs1(q,x);
			}
			else
			{
				if(cnt[p]!=cnt[1])check_min(dis,df[p]);
			}
		if(ex[p])df[p]=0;
	}
	void initialize()
	{
		static char tmp[N];
		read(n);
		for(int i=1,u,v;i<n;i++)
			read(u),read(v),add(u,v);
		scanf("%s",tmp+1);
		for(int i=1;i<=n;i++)ex[i]=tmp[i]=='1';
	}
	void solve()
	{
		initialize();
		dfs0(1),dfs1(1);

//		for(int i=1;i<=n;i++)
//			printf("%d : %d , %d\n",i,f[i].x,f[i].y);

		ll ans=0;
		for(int i=1;i<=n;i++)
		{
			ans+=std::max(0,std::min(f[i].x-1,f[i].y+1)-df[i]+1);
		}
		printf("%lld\n",ans+1);
	}
}
int main()
{
	gg::solve();
	return 0;
}


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

int gcd(int a, int b){
    if (a == b)
        return a;
    if (a < b)
        return gcd(b, a);
    if (a % b == 0){
        return b;
    }else{
        int r = a % b;
        gcd(b, r);
    }
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;i++)
        cin >> A[i];
    int gl = A[0], gr = A[N-1];
    vector<int> L(N), R(N);
    for (int i=0;i<N;i++){
        gl = gcd(gl, A[i]);
        gr = gcd(gr, A[N-1-i]);
        L[i] = gl;
        R[i] = gr;
    }
    int ans = max(L[N-2], R[N-2]);
    for (int i=0;i<N-2;i++){
        ans = max(ans, gcd(L[i], R[N-3-i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b,c,d = na()

print(max(a*c,a*d,b*c,b*d))

Measured memory_bytes: 9180
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

import java.util.*;

public class Main{
  static final boolean DEBUG = true;

  public static void main(String[] args){
    FastScanner sc = new FastScanner();

    String s = sc.next();

    boolean all = true;
    for(char ch = 'a'; ch <= 'c'; ch++){
      boolean exist = false;
      for(int j = 0; j < 3; j++){
        if(ch == s.charAt(j)){
          exist = true;
          break;
        }
      }
      if(!exist){
        all = false;
        break;
      }
    }

    if(all) System.out.println("Yes");
    else System.out.println("No");
  }
}

class FastScanner {
  private static final InputStream in = System.in;
  private static final PrintWriter out = new PrintWriter(System.out);
  private final byte[] buffer = new byte[2048];
  private int p = 0;
  private int buflen = 0;

  public FastScanner(){
  }

  private boolean hasNextByte() {
    if(p < buflen){
      return true;
    }
    p = 0;
    try{
      buflen = in.read(buffer);
    }catch (IOException e) {
      e.printStackTrace();
    }
    if(buflen <= 0){
      return false;
    }
    return true;
  }

  public boolean hasNext() {
    while(hasNextByte() && !isPrint(buffer[p])){
      p++;
    }
    return hasNextByte();
  }

  private boolean isPrint(int ch) {
    if(ch >= '!' && ch <= '~'){
      return true;
    }
    return false;
  }

  private int nextByte() {
    if(!hasNextByte()){
      return -1;
    }
    return buffer[p++];
  }

  public String next() {
    if(!hasNext()){
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = -1;
    while(isPrint((b = nextByte()))){
      sb.appendCodePoint(b);
    }
    return sb.toString();
  }

  public int nextInt() {
    return Integer.parseInt(next());
  }

  public long nextLong() {
    return Long.parseLong(next());
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}


Measured memory_bytes: 21204