akhauriyash/Code-Regression huggingface dataset:
N = int(input())
d = {}
a = [int(x) for x in input().split()]

for i in a :
    if i in d.keys() :
        d[i] += 1
    else :
        d[i] = 1
        
    if i - 1 in d.keys() :
        d[i - 1] += 1
    else :
        d[i - 1] = 1
        
    if i + 1 in d.keys() :
        d[i + 1] += 1
    else :
        d[i + 1] = 1
        
print(max(d.values()))

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

int main() {
  int N,K,X,Sum=0 ;
 cin >>N >>K;
   for (int i = 0; i<N ; i++) {
   cin >>X;  
   if (X <= K/2){
     Sum += X;}
   else {
     Sum += (K-X);}
   } 
   cout << Sum*2 <<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		while(true) {
        int a = sc.nextInt();
        String op = sc.next();
        int b = sc.nextInt();
        switch(op){
            case "+":
                System.out.println(a + b);
                break;
            case "*":
                System.out.println(a * b);
                break;
            case "-":
                System.out.println(a - b);
                break;
            case "/":
                System.out.println(a / b);
                break;
            default:
                System.exit(0);
        }
		}
        
    }
}


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

using namespace std;

#define _for(i,j,N) for(int i = (j); i < (N);i++)

int main()
{
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int cnt = 0;
    _for(i,0,A+1){
        _for(j,0,B+1){
            int m = X-i*500-j*100;
            if(m >= 0&&m%50 == 0&&m/50 <= C)
                cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

road_h = [[0 for i in range(6)] for j in range(7)] #?¨??????????
road_v = [[0 for i in range(7)] for j in range(6)] #????????????
ax = ay = 1
ad_list = ['L', 'R', 'U', 'D']

for i in range(9):
    line = str(raw_input())
    if i % 2 == 0:
        for j in range(4):
            if line[j] == '1':
                road_h[1+i/2][1+j] += 1
    else:
        for j in range(5):
            if line[j] == '1':
                road_v[1+i/2][1+j] += 1

ad = 1
ax += 1
ans = 'R'
while True:
    if ax == 1 and ay == 1:
        break
    if ad == 0:     #?????????
        if road_v[ay][ax]:
            ay += 1
            ad = 3
        elif road_h[ay][ax-1]:
            ax -= 1
        elif road_v[ay-1][ax]:
            ay -= 1
            ad = 2
        else:
            ax += 1
            ad = 1
    elif ad == 1:   #?????????
        if road_v[ay-1][ax]:
            ay -= 1
            ad = 2
        elif road_h[ay][ax]:
            ax += 1
        elif road_v[ay][ax]:
            ay += 1
            ad = 3
        else:
            ax -= 1
            ad = 0
    elif ad == 2:   #?????????
        if road_h[ay][ax-1]:
            ax -= 1
            ad = 0
        elif road_v[ay-1][ax]:
            ay -= 1
        elif road_h[ay][ax]:
            ax += 1
            ad = 1
        else:
            ay += 1
            ad = 3
    elif ad == 3:   #?????????
        if road_h[ay][ax]:
            ax += 1
            ad = 1
        elif road_v[ay][ax]:
            ay += 1
        elif road_h[ay][ax-1]:
            ax -= 1
            ad = 0
        else:
            ay -= 1
            ad = 2
    ans = ans + ad_list[ad]
print ans

Measured memory_bytes: 6296
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//long.Parseはstringをlongに変換。
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] remains = new long[3];//4で割った余りが0,(1,3),2
    bool answer = false;

    for(int i = 0; i < n; i++)
    {
      if(nums[i] % 4 == 0) remains[0]++;
      else if(nums[i] % 4 == 2) remains[2]++;
      else remains[1]++;
    }

    if(remains[2] >= 1 && remains[0] >= remains[1]) answer = true;
    else if(remains[2] == 0 && remains[0]+1 >= remains[1]) answer = true;
    
		Console.WriteLine((answer) ? "Yes" : "No");
	}
}

Measured memory_bytes: 18784
//                             In The Name Of Allah
//                             	Mohammad Hosseini
//                                     185
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 400, OO = 724249387, T = (1 << 20) + 10, M = 998244353, P = 6151, SQ = 280, lg = 24;
typedef pair <int, int> pii;
// dp[i][j][k]
// i,omin , j ta bash pol, kk ta ham ezaf
// dp[i][j][k] = dp[i - 1][j][k + cnt[i]] + dp[i - 1][j][k + cnt[i] - 1], ..., dp[i -1][j][k];
// dp[i][j][k] += dp[i - 1][j - 1][k - 1] + dp[i - 1][j - 2][k - 2] + ... + dp[i - 1][j - k][0];
// sum[i][j][k] = sum[i][j][k - 1] + dp[i][j][k];
// dp[i][j][k] = sum[i - 1][j][k + cnt[i]] - sum[i - 1][j][k - 1];
// cur[i][j][k] = cur[i][j - 1][k - 1] + dp[i][j][k];
// dp[i][j][k] += cur[i - 1][j - 1][k - 1];
int dp[N][N][N], sum[N][N][N], cnt[N], cur[N][N][N];

int32_t main() {
 	use_fast;
	string s;
	int l;
	cin >> s >> l;
	vector <int> v;
	int cmp = 0, n = 1;
	for(auto u : s) {
		if(u == '0') {
			cnt[n++] = cmp;
			cmp = 0;
			continue;
		}
		cmp++;
	}
	if(cmp)
		cnt[n++] = cmp;
	l = min(l, (int)350);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= l; j++) {
			for(int k = 0; k + cnt[i] <= (int)s.size(); k++) {
				if(i == 0) {
					if(k == 0)
						dp[i][j][k] = 1;
				}
				else {
					dp[i][j][k] = sum[i - 1][j][k + cnt[i]];
					if(k)
						dp[i][j][k] -= sum[i - 1][j][k - 1];
					if(i && j && k)
						dp[i][j][k] += cur[i - 1][j - 1][k - 1];
					dp[i][j][k] = (dp[i][j][k] + M) % M;
				}
				cur[i][j][k] = sum[i][j][k] = dp[i][j][k];
				if(k)
					sum[i][j][k] = (sum[i][j][k - 1] + dp[i][j][k]) % M;
				if(k && j)
					cur[i][j][k] = (cur[i][j][k] + cur[i][j - 1][k - 1]) % M;
			}	
		}
	}
	cout << dp[n - 1][l][0] << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/


Measured memory_bytes: 505064
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
ll power(ll a,ll b,ll mod){  ll ans=1;  while(b>0){
  if(b&1){ ans=(ans*a)%mod;} a=(a*a)%mod;  b=b/2; } return ans;}

int main(){
FIO
ll a,b,c,k;
cin>>a>>b>>c>>k;
ll count=0;
while(b<=a){
    b=b*2;
    count++;
}
while(c<=b){
    c=c*2;
    count++;
}
if(count<=k){
    cout<<"Yes"<<endl;
}else{
 cout<<"No"<<endl;
}
}


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

int a[12][12];
const int INF = 1001001001;
//固定値入力

int main () {
  int n,m,x;cin>>n>>m>>x;
  vector<int>c(n);
  for (int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++)cin>>a[i][j];
  }
//入力受け取り
  int ans =INF;
  for(int s=0;s<(1<<n);s++){//集合sの作成
    int cost =0;
    vector<int>d(m);//判定配列
    for(int i=0;i<n;i++){
      if(s>>i&1){//集合に対して条件判定
        cost += c[i];
        for(int j=0;j<m;j++)d[j] += a[i][j];
      }//条件があった場合のコストと理解値入力
    }

    bool ok = true;
    for(int j=0;j<m;j++)if(d[j] < x)ok = false;
    if(ok) ans = min(ans ,cost);  
    //条件判定＞ループ
  }
  //解答提出
  if (ans == INF){
    cout << -1 << endl;
  }else{
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3612
class Dice:
    def __init__(self):
        self.dice = [
                    [0, 1, 2, 3, 4, 5],
                    [0, 2, 4, 1, 3, 5],
                    [0, 4, 3, 2, 1, 5],
                    [0, 3, 1, 4, 2, 5],
                    [1, 5, 2, 3, 0, 4],
                    [1, 2, 0, 5, 3, 4],
                    [1, 0, 3, 2, 5, 4],
                    [1, 3, 5, 0, 2, 4],
                    [2, 1, 5, 0, 4, 3],
                    [2, 5, 4, 1, 0, 3],
                    [2, 4, 0, 5, 1, 3],
                    [2, 0, 1, 4, 5, 3],
                    [3, 1, 0, 5, 4, 2],
                    [3, 0, 4, 1, 5, 2],
                    [3, 4, 5, 0, 1, 2],
                    [3, 5, 1, 4, 0, 2],
                    [4, 0, 2, 3, 5, 1],
                    [4, 2, 5, 0, 3, 1],
                    [4, 5, 3, 2, 0, 1],
                    [4, 3, 0, 5, 2, 1],
                    [5, 1, 3, 2, 4, 0],
                    [5, 2, 1, 4, 3, 0],
                    [5, 4, 2, 3, 1, 0],
                    [5, 3, 4, 1, 2, 0]]

    def math(self, dice_p1, dice_p2):
        dice_t = []
        same = "No"
        for dice_p in self.dice:
            for i in range(6):
                dice_t.append(dice_p1[dice_p[i]])
            if dice_t == dice_p2:
                same = "Yes"
            dice_t = []
        return same

d = Dice()
dice_p1 = [int(dice_p1) for dice_p1 in input().split()]
dice_p2 = [int(dice_p2) for dice_p2 in input().split()]
print(d.math(dice_p1, dice_p2))

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int cnt = 0;
  for (int i = 0; i < N - 2; i++) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
      cnt++;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#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()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    printf("%.9f %d\n", w*h/2.0, (x == w/2.0 && y == h/2.0));
}

Measured memory_bytes: 3752
a,b,k=map(int,input().split())
li=[]

for i in range(a,min(b+1,a+k)):
    li.append(i)

for j in range(b,max(a-1,b-k),-1):
    li.append(j)

li=list(set(li))
li.sort()

for i in li:
    print(i)

Measured memory_bytes: 3064
N = int(input())
C = list(input())

r = N-1
l = 0
ans = 0

while C[r] == 'W':
    r -= 1
    if r < 0:
        print(0)
        exit()
while C[l] == 'R':
    l += 1
    if l >= N:
        print(0)
        exit()
while l < r:
    C[r], C[l] = C[l], C[r]
    ans += 1
    while C[r] == 'W':
        r -= 1
        if r < 0:
            break
    while C[l] == 'R':
        l += 1
        if l >= N:
            break
print(ans)



Measured memory_bytes: 10816
# -*- coding: utf-8 -*-
from collections import defaultdict
from operator import itemgetter
def solve():
    n = int(input())
    V = list(map(int, input().split()))
    l = defaultdict(int)
    u = defaultdict(int)
    for i in range(0,n,2):
        l[V[i]] += 1
        u[V[i+1]] += 1

    l = sorted(list(l.items()),key=itemgetter(1))[::-1]
    u = sorted(list(u.items()),key=itemgetter(1))[::-1]
    if len(l) == len(u) == 1:
        if l[0][0] != u[0][0]:
            res = 0
        else:
            res = min(l[0][1], u[0][1])
    else:
        if l[0][0] != u[0][0]:
            res = sum(map(itemgetter(1), l[1:])) + sum(map(itemgetter(1), u[1:]))
        elif len(u) == 1 or (len(l) > 1 and l[1][1]+u[0][1] > l[0][1]+u[1][1]):
            res = l[0][1] + sum(map(itemgetter(1), l[2:])) + sum(map(itemgetter(1), u[1:]))
        else:
            res = u[0][1] + sum(map(itemgetter(1), l[1:])) + sum(map(itemgetter(1), u[2:]))

    return str(res)

if __name__ == '__main__':
    print(solve())



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

using namespace std;
typedef long long ll;

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

  int a, b;
  cin >> a >> b;

  if (a * b & 1) cout << "Odd" << "\n";
  else cout << "Even" << "\n";
}


Measured memory_bytes: 3584
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int p = in.nextInt();
		int q = in.nextInt();
		int r = in.nextInt();
		System.out.println(solve(p, q, r));
		in.close();
	}

	private static int solve(int p, int q, int r) {
		int a = p + q;
		if (a > q + r)
			a = q + r;
		if (a > r + p)
			a = r + p;
		return a;
	}
}

Measured memory_bytes: 23252
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author P.Alizadeh
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll,ll>     pll;
typedef complex<ld>     cld;

#define all(x)          x.begin(),x.end()
#define Sort(x)         sort(all(x))
#define kill(x)         return cout << x << endl, 0;
#define Mp              make_pair
#define X               first
#define Y               second
#define sep             " "
#define endl            "\n"
#define fastio          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define ld_io           cout << setprecision(10) << fixed;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll md) {
    if (!b)
        return 1;
    if (b & 1)
        return a * pw(a * a % md, b / 2, md) % md;
    return pw(a * a % md, b / 2, md) % md;
}

ll inmod(ll a, ll m) {
    a = (-m < a && a < m) ? a : a % m;
    if (a < 0)  a += m;
    return a;
}

const ll MAXN = 1e5 + 10,
         INF  = 8e18,
         MOD  = 1e9 + 7,
         LOG  = 32;
//const ld PI   = M_PI;

ll n, d, a[MAXN], dp[MAXN][110], x;
string s;

int main()
{
    fastio;
    //ld_io;

    cin >> s >> d;
    n = s.size();
    for (ll i = 0; i < n; i++)
        a[i + 1] = s[i] - '0';

    for (ll i = 0; i <= a[1]; i++)
        dp[1][i % d]++;
    x = a[1] % d;

    for (ll i = 2; i <= n; i++) {
        for (ll j = 0; j < d; j++) {
            for (ll k = 0; k < 10; k++) {
                ll p = inmod(j - k, d);
                if (p == x && k > a[i])
                    dp[i][j] += dp[i - 1][p] - 1 + MOD;
                else
                    dp[i][j] += dp[i - 1][p];
                dp[i][j] %= MOD;
            }
        }
        x = (x + a[i]) % d;
    }

    cout << (dp[n][0] - 1 + MOD) % MOD << endl;

    return 0;
}



Measured memory_bytes: 12544
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }


template<typename InpIt, typename OutIt, typename Val, typename Cmp>
void stackAlgorithm(InpIt beg, InpIt end, OutIt out, Cmp cmp = Cmp()) {
	int n = (int)std::distance(beg, end);
	for(int i = 0; i < n; ++ i) {
		int k = i;
		while(k > 0 && cmp(beg[k - 1], beg[i]))
			k = out[k - 1];
		out[i] = k;
	}
}
template<typename InpIt, typename OutIt, typename Cmp>
void stackAlgorithm(InpIt it, InpIt end, OutIt out, Cmp cmp = Cmp()) {
	return stackAlgorithm<InpIt, OutIt, typename iterator_traits<InpIt>::value_type, Cmp>(it, end, out, cmp);
}

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> a(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &a[i]);
		vector<int> L(N), R(N);
		stackAlgorithm(a.begin(), a.end(), L.begin(), greater_equal<int>());
		stackAlgorithm(a.rbegin(), a.rend(), R.rbegin(), greater_equal<int>());
		rep(i, N) R[i] = N - 1 - R[i];
		ll ans = 0;
		rep(i, N)
			ans += (ll)a[i] * (R[i] + 1 - i) * (i + 1 - L[i]);
		printf("%lld\n", ans);
	}
	return 0;
}


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

const int MAXN = 1e5;
vector<int> dp(MAXN,-1);
vector<vector<int>> from(MAXN);

int dfs(int v){
	if(dp[v] != -1) return dp[v];
	
	if(from[v].empty()) return dp[v] = 0;
	int res = 0;
	for(auto w : from[v]){
		res = max(res, dfs(w)+1);
	}
	
	return dp[v] = res;
}

int main(){
	int n,m;
	cin >> n >> m;
	
	rep(i,m){
		int x,y;
		cin >> x >> y;
		--x; --y;
		from[y].push_back(x);
	}
	
	rep(i,n) dfs(i);
	
	int res = 0;
	rep(i,n) res = max(res,dp[i]);
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 10624
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  a=pM(split(readline()))
  l=fill(0,n); for i=a; l[i]+=1; end
  ans=0; for i=l; ans+=binomial(i,2) end
  for i=a;
    println(ans-l[i]+1)
  end    
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}
struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false; //閉路検出
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	UF ufa(4);
	VI ct(4);
	rep(i,3){
		int a,b;
		cin >>a >>b;
		ufa.unite(a-1,b-1);
		ct[a-1] +=1;
		ct[b-1] +=1;
	}
	set<int> st;
	rep(i, 4) st.insert(ufa.find(i));
	rep(i, 4) if(ct[i] >2) { puts("NO");return 0;}
	
	if(sz(st)!=1){ puts("NO");return 0;}
	puts("YES");
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007

long long Q, H, S, D, N;
long long _Q[4];
long long _Q2[3];

void solve() {
	cin >> Q >> H >> S >> D >> N;
	Q *= 4; H *= 2;
	_Q[0] = Q * 2; _Q[1] = H * 2; 
	_Q[2] = S * 2; _Q[3] = D;

	_Q2[0] = _Q[0] / 2; _Q2[1] = _Q[1] / 2;
	_Q2[2] = _Q[2] / 2;

	sort(_Q, _Q + 4);
	sort(_Q2, _Q2 + 3);
	long long ans = _Q[0] * (N / 2);
	if (N % 2 == 1) ans += _Q2[0];
	
	cout << ans << endl;
}

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

Measured memory_bytes: 384
def d_triangles():
    from bisect import bisect_left
    N = int(input())
    L = sorted([int(i) for i in input().split()])

    ans = 0
    for min_index in range(N - 2):
        for second_index in range(min_index + 1, N - 1):
            a, b = L[min_index], L[second_index]
            max_index = bisect_left(L, a + b)
            ans += max_index - (second_index + 1)
    return ans

print(d_triangles())

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; ++i) cin >> p[i];
	int flag = 0;
	for (int i = 0; i < n; ++i)
		if (p[i] != i + 1) flag++;
	if (flag <= 2) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

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

    int N; cin >> N;
    int sumL = 0, maxL = 0;
    for (int i = 0; i < N; i++) {
        int L; cin >> L;
        sumL += L;
        maxL = max(maxL, L);
    }
    cout << (maxL < sumL - maxL ? "Yes" : "No") << "\n";
}

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

vector<int> g[100005];
int n,m;
int in[100005];
int depth[100005];
int ans[100005];

int main() {
  cin >> n >> m;
  for(int i = 0; i < n+m-1; i++) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    in[b]++;
  }

  vector<int> to;
  queue<int> q;
  for(int i = 0; i < n; i++) {
    if(in[i] == 0) {
      q.push(i);
      ans[i] = -1;
    }
  }
      
  while(!q.empty()) {
    int v = q.front();
    to.push_back(v);
    q.pop();
    for(int i = 0; i < g[v].size(); i++) {
      int u = g[v][i];
      in[u]--;
      if(in[u] == 0) {
	q.push(u);
      }
    }
  }


  for(int i = 0; i < to.size(); i++) {
    int v = to[i];
    for(int j = 0; j < g[v].size(); j++) {
      int u = g[v][j];
    
      depth[u] = depth[v] + 1;
      ans[u] = v;
    }
  }

  for(int i = 0; i < n; i++) cout << ans[i] + 1 << endl;
}
  
  
  


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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int A, B;
  cin >> A >> B;
  int a[3] = {};
  a[A - 1] = 1;
  a[B - 1] = 1;
  FOR(i, 3) {
    if (a[i] == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int ans=0;
	int x=100;
	int t;
	cin>>t;
	while(x<t)
	{
		++ans;
		x=x+(x/100);
	}
	cout<<ans;
	#ifdef ANIKET_GOYAL
		cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
} 

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N, A[100010];

int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%d", A + i);
	if(N % 3) {
		int t1 = *max_element(A+1, A+1+N);
		int t2 = *min_element(A+1, A+1+N);
		if(t1 != t2) puts("No");
		else puts("Yes");
	}
	else {
		map <int, int> Mx;
		for(int i=1;i<=N;i++) Mx[A[i]]++;
		if(szz(Mx) > 3) {
			puts("No");
			return 0;
		}
		vector <int> w;
		for(pii e : Mx) {
			if(e.Se % (N / 3)) {
				puts("No");
				return 0;
			}
			int t1 = e.Se / (N / 3);
			rep(j, t1) w.pb(e.Fi);
		}
		if((w[0] ^ w[1] ^ w[2]) == 0) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
        int  n, a, b, s = 0, sum = 0, req = 0;
        cin >> n >> a >> b;
        for(int i = 1; i <= n; i++){
                //s = i.size();
                int x = i;
                sum = 0;
                while(x){
                        sum = sum + (x % 10);
                        x /= 10;
                }
                if(sum >= a && sum <= b) req = req + i;
        }
        cout << req << endl;

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int r[100005],r2[100005],r3[1000005];
int main()
{
    long long int a,b,c,d,e,f,g,k;

    string s;

    while(cin>>a)
    {
        for(int i=1;i<=a;i++)
        {
            cin>>r[i];
        }


    b=0;
      for(int i=1;i<=a;i++)
      {
          if(i-1>=1&&i+1<=a&&((r[i]>r[i-1]&&r[i]<r[i+1])||(r[i]<r[i-1]&&r[i]>r[i+1])))
             {
                 b++;
             }
      }
      cout<<b<<endl;


    }








    return 0;
}


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

int n, m;
int parent[1000];			//親の番号
int indent_table[1000];		//そのインデントに対する、親の番号
map<string,int> names;		//名前と番号の対応

//XがYの親であるかどうかを判定。
bool is_parent(int x_num, int y_num){
	if( x_num == parent[y_num] ){ return true; }
	return false;
}

//XとYが兄弟であるか(すなわち、親が同じであるか)を判定。
bool is_sibling(int x_num, int y_num){
	if( parent[x_num] == parent[y_num] ){ return true; }
	return false;
}

//XがYの先祖であるかを判定。
//Yの親を順に辿っていき、途中でXと等しくなったらtrueを返す。
bool is_ancestor(int x_num, int y_num){
	while( y_num >= 0 ){
		if( x_num == y_num ){ return true; }
		y_num = parent[y_num];
	}
	return false;
}

int main(){
	string person;

	while(true){
		cin >> n >> m;
		if( m == 0 ) break;

		names.clear();

		indent_table[0] = -1;	//最初の人に親はいないので、-1としておく。

		cin.ignore();	//改行が邪魔なので、一文字飛ばす
		for(int i = 0; i < n; ++i){
			getline(cin, person);
			int indent = person.find_first_not_of(" ");
				//インデントを数える。
				//インデントを除いた person.substr(indent) が、実際の名前

			names[person.substr(indent)] = i;	//その人をi番とする。
			parent[i] = indent_table[indent];	//親の番号を決定する。
			indent_table[indent + 1] = i;		//子のためにテーブルを更新。
		}
		
		string X, Y, rel;	//X, Yおよびその関係
		string ign;	//無視する文字列
		for(int i = 0; i < m; ++i){
			cin >> X >> ign >> ign >> rel >> ign >> Y;
				//is, (a/an/the), of は無視する。
			Y.resize(Y.size() - 1);	//最後に . が含まれるので、除去。

			int x_num = names[X];
			int y_num = names[Y];	//XおよびYに対応する番号を取得
			bool ans = false;
			
			if( rel == "child" ){
				ans = is_parent(y_num, x_num);
			}
			else if( rel == "parent" ){
				ans = is_parent(x_num, y_num);
			}
			else if( rel == "sibling" ){
				ans = is_sibling(x_num, y_num);
			}
			else if( rel == "descendant" ){
				ans = is_ancestor(y_num, x_num);
			}
			else if( rel == "ancestor" ){
				ans = is_ancestor(x_num, y_num);
			}
			
			if( ans ){ cout << "True\n"; }
			else{ cout << "False\n"; }
		}
		
		cout << '\n';
	}
}

Measured memory_bytes: 1332
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
BC.sort(key = lambda x: x[1])
A.sort()
j = M - 1
res = 0
for i in range(N):
  if len(A) == 0:
    break
  if len(A) <= i:
    break
  if A[i] < BC[j][1]:
    A[i] = BC[j][1]
    BC[j][0] -= 1
    if BC[j][0] == 0:
      if j == 0:
        break
      else:
        j -= 1
res += sum(A)
print(res)

Measured memory_bytes: 32960
#include<stdio.h>
#include<math.h>
int main(){
	int a;
	int b;
	int c;
	int d;
	scanf("%d %d %d %d\n",&a, &b, &c, &d);
	if((a-1)*(b-1)*(c-1)*(d-1)==0&&(a-7)*(b-7)*(c-7)*(d-7)==0&&(a-9)*(b-9)*(c-9)*(d-9)==0&&(a-4)*(b-4)*(c-4)*(d-4)==0){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D2019PCA2
{
    class Program
    {
        static void Main(string[] args)
        {
            //スペース区切りで入力されたデータは１番目→input[0]、２番目→input[1] .......の形で受け取られる
            //配列の添え字は０から始める
            //受け取ったデータは文字型なので、整数型に変える
            string[] input = Console.ReadLine().Split(' ');
            int R = int.Parse(input[0]);
            int G = int.Parse(input[1]);
            int B = int.Parse(input[2]);
            int N = int.Parse(input[3]);
            int ans = 0;
            int check = 0;
            for (int r = 0; r <= N/R; r++)
            {
                for (int g = 0; g <= N/G; g++)
                {
                    check = N - (R * r + G * g);
                    if (check>=0&&check%B==0)
                    {
                        ans++;
                    }
                }
            }
            Console.WriteLine(ans);//答えを出力する

        }
    }
}


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

int main(){
	int n, m, total, aprobados = 0;
	vector<int> v;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		v.push_back(a);
		total += a;
	}
	double min = ((double)1) / (4*m) * total;
	for(int x : v){
		if((double)x >= min)
			aprobados++;
	}
	if(aprobados >= m)
		cout << "Yes" << '\n';
	else 
		cout << "No" << '\n';

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b[5]={0};
	int shijian=0;
	int c=0;
	for(int i=0;i<5;i++){
		cin>>a;
		shijian+=a;
		a%=10;
		if(a!=0)
		{
			shijian+=(10-a);
			if(c<(10-a)) c=10-a;
		}
	}
	shijian-=c;
	cout<<shijian<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(long long i = a; i < b; i++)
#define rrep(i,a,b) for(long long i = a; b < i; i--)
#define print(a) cout << a << "\n"
#define dump(a) for(auto x : a) cout << x << " "; cout << "\n"
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using namespace std;
typedef long long ll;
using vi   = vector<int>;
using vll  = vector<ll>;
using vs   = vector<string>;
using vvi  = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvs  = vector<vector<string>>;

int main()
{
  int N;cin >> N;
  ll L[N];
  cin >> L[0];
  rep(i,1,N) {
    cin >> L[i];
    ll idx = i;
    while (idx != 0 && L[idx - 1] > L[idx]) {
      ll tmp = L[idx];
      L[idx] = L[idx - 1];
      L[idx - 1] = tmp;
      --idx;
    }
  } 
  ll total = 0;

  rep(i,0,N - 2) {
    rep(j,i+1,N) {
      rep(k,j+1,N) {
        if (L[i] == L[j]) continue;
        if (L[i] == L[k]) continue;
        if (L[j] == L[k]) continue;
        
        if (L[k] - L[j] >= L[i]) continue;
        total++;
      }
    }
  }
  print(total);

  return 0;
}




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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n,x=MI()
ls=LI()
dp=[0 for i in range(n+1)]
for i in range(n):
    dp[i+1]=dp[i]+ls[i]
#print(dp)
count=0
for d in dp:
    if d<=x:
        count+=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   int a,b,c,d=0;
   cin>>a>>b>>c;
   for(int i=a;i<=b;i++)
   {
        if(c%i==0){d=d+1;}  
   }
   cout<<d<<endl;
}



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

int main(){
    int i;
    string s;
    cin >> s;
    for(i=1; i<s.size(); i++){
        if(s[i-1] == s[i]){
            cout << i << ' ' << i+1;
            return 0;
        }
        if(i > 1 && s[i-2] == s[i]){
            cout << i-1 << ' ' << i+1;
            return 0;
        }
    }
    cout << "-1 -1";
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.lang.*;

class Mod{
    static final long MOD = 1000_000_007;
    static final long[] fact = makeFactorialArray(1000000);
    static final long[] factInv = makeInversedArray(fact);

    public static long add(long a, long b){
        long tmp = (a+b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long adds(long... ar){
        long ans=0;
        for(long x:ar) ans = Mod.add(ans, x);
        return ans;
    }
    public static long sub(long a, long b){
        return add(a,-b);
    }
    public static long mult(long a, long b){
        long tmp = (a*b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long mults(long... ar){
        long ans=1;
        for(long x:ar) ans = Mod.mult(ans, x);
        return ans;
    }
    public static long power(long a, long x){ //calculate a^x
        if(x<0)return 0;
        if(x==0)return 1;
        if(x%2==0) {
            long half = power(a,x/2);
            return mult(half,half);
        }
        return (a*power(a,x-1)) % MOD;
    }
    public static long inverse(long a){
        return power(a,MOD-2);
    }
    public static long div(long a, long b){
        return mult(a, inverse(b));
    }
    public static long[] makeFactorialArray(int size){
        long[] array = new long[size];
        array[0]=1;
        for(int i=1;i<size;i++){
            array[i]=mult(array[i-1],i);
        }
        return array;
    }
    public static long[] makeInversedArray(long[] original){
        long[] array = new long[original.length];
        for(int i=0;i<original.length;i++){
            array[i] = inverse(original[i]);
        }
        return array;
    }
    public static long combination(int n, int r){
        if(n<0 || r<0 || n<r) return 0;
        return mult(fact[n], mult(factInv[r],factInv[n-r]));
    }

}

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int n=0; n<N; n++) A[n]=sc.nextInt()-1;
        int[] B = new int[N];
        for(int n=0; n<N; n++) B[n]=sc.nextInt();
        int[] C = new int[N-1];
        for(int n=0; n<N-1; n++) C[n]=sc.nextInt();

        long sat = B[A[0]];
        for(int n=1; n<N; n++){
            sat += B[A[n]];
            if(A[n]-A[n-1]==1) sat += C[A[n-1]];
        }
        System.out.println(sat);

    }
}


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

#define REP(i,n) for(int i=0;i<(n);++i)
const long long INF = 1LL<<60;
const long long mod=1e9+7;

int main(){
    int N, D;
    cin >> N >> D;
    int x[11][11];
    REP(i,N){
        REP(j,D) cin >> x[i][j];
    }
    int ans = 0;
    REP(i,N - 1){
        for(int j = i + 1; j < N; ++j){
            int sqdist = 0;
            REP(k,D) sqdist += (x[j][k] - x[i][k]) * (x[j][k] - x[i][k]);
            double dist = sqrt(sqdist);
            if(ceil(dist) == floor(dist)) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S=input()
s1 = S[0:int((len(S)-1)/2)]
s2 = S[int((len(S)+3)/2-1):len(S)]
if ((S == S[::-1]) & (s1 == s1[::-1]) & (s2 == s2[::-1])):
    print("Yes")
else:
    print("No")


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

int main() {
  long long n, m; cin >> n >> m;
  vector<long long> p(m);
  vector<string> s(m);
  for(int i = 0; i < m; i++){
    cin >> p.at(i) >> s.at(i);
    p.at(i)--;
  }
  vector<int> seitou(n, 0);
  vector<int> pe(n, 0);
  long long wa = 0;
  for(int i = 0; i < m; i++){
    if(seitou.at(p.at(i)) == 0){
      if(s.at(i) == "WA"){
        pe.at(p.at(i))++;
      }else{
        seitou.at(p.at(i)) = 1;
      }
    }
  }
  long long se = 0;
  for(int i = 0; i < n; i++){
    se += seitou.at(i);
    if(seitou.at(i) == 1) wa += pe.at(i);
  }
  cout << se << " " << wa;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

// ====================================================================

int main() {
  vector<ll> nC2;
  for (int i = 0; i * (i - 1) / 2 <= 100100; i++) {
    nC2.push_back(i * (i - 1) / 2);
  }

  ll n;
  cin >> n;
  int aru = 0;
  for (int i = 0; i < nC2.size(); i++) {
    if (nC2[i] == n) aru = i;
  }

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

  cout << aru << endl;

  vector<int> g[aru];
  int count = 1;
  for (int i = 0; i < aru - 1; i++) {
    for (int j = i + 1; j < aru; j++) {
      g[i].push_back(count);
      g[j].push_back(count);
      count++;
    }
  }

  for (int i = 0; i < aru; i++) {
    cout << g[i].size() << " " << g[i] << endl;
  }
}


Measured memory_bytes: 2304
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,m,first[100010],dep[100010],s[100010],fa[100010];
struct edge{
	int to,next;
}a[200010];
int cnte=0;
inline void add(int u,int v){
	a[++cnte]=(edge){v,first[u]};first[u]=cnte;
	a[++cnte]=(edge){u,first[v]};first[v]=cnte;
}
int u,v;
void dfs(int uu,int f){
//	cout<<"dfs "<<uu<<' '<<f<<'\n';
	int i,vv;
	dep[uu]=dep[f]+1;s[uu]=(dep[uu]%2)?-1:1;fa[uu]=f;
	for(i=first[uu];~i;i=a[i].next){
		vv=a[i].to;if(vv==f) continue;
		if(dep[vv]) u=uu,v=vv;
		else dfs(vv,uu),s[uu]+=s[vv];
	}
//	cout<<"finish "<<uu<<' '<<s[uu]<<'\n';
}
int lca(int u,int v){
	if(dep[u]>=dep[v]) swap(u,v);
//	cout<<"getlca "<<u<<' '<<v<<'\n';
	while(dep[fa[v]]>=dep[u]) v=fa[v];
	while(u!=v&&dep[u]>1) u=fa[u],v=fa[v];
	return u;
}
int b[100010],cnt;
int main(){
	memset(first,-1,sizeof(first));
	n=read();m=read();int i,t1,t2;
	for(i=1;i<=m;i++){
		t1=read();t2=read();
		add(t1,t2);
	}
	dfs(1,0);int ans=0,mid;
	if(m==n-1){
		if(s[1]){
			puts("-1");return 0;
		}
		for(i=1;i<=n;i++) ans+=abs(s[i]); 
		cout<<ans;return 0;
	}
//	cout<<u<<' '<<v<<' '<<mid<<'\n';
	if(((dep[u]^dep[v])&1)==0){//奇 
		if(s[1]&1){
			puts("-1");return 0;
		}
		int w=(-s[1])/2;ans=abs(w);
		while(u) s[u]+=w,u=fa[u];
		while(v) s[v]+=w,v=fa[v];
		for(i=1;i<=n;i++) ans+=abs(s[i]);
		cout<<ans;return 0;
	}
	if(s[1]){
		puts("-1");return 0;
	}
	mid=lca(u,v);
	while(u!=mid) b[++cnt]=s[u],dep[u]=-1,u=fa[u];
	while(v!=mid) b[++cnt]=-s[v],dep[v]=-1,v=fa[v];
	b[++cnt]=0;
	nth_element(b+1,b+(cnt/2),b+cnt+1);int w=b[cnt/2];
	for(i=1;i<=n;i++) if(~dep[i]) ans+=abs(s[i]);
	for(i=1;i<=cnt;i++) ans+=abs(b[i]-w);
	cout<<ans<<'\n';
}

Measured memory_bytes: 8448
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N, M int
  NextInt(&N, &M)
  G := make([][]int, N)
  for i := range G { G[i] = make([]int, 0) }
  var a, b int
  for i := 0; i < M; i++ {
    NextInt(&a, &b)
    a--; b--
    G[a] = append(G[a], b)
    G[b] = append(G[b], a)
  }
  P := make([]int, N)
  for i := range P[1:] { P[i + 1]-- }
  Q := make([]int, N)
  pos := 1
  for _, q := range Q {
    for _, v := range G[q] {
      if P[v] >= 0 { continue }
      P[v] = q
      Q[pos] = v
      pos++
    }
  }
  Write("Yes")
  for _, p := range P[1:] { Write(p + 1) }
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 19284
#include<bits/stdc++.h>
#include<cassert>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds; 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define inf INT_MAX
#define llinf LONG_LONG_MAX

const int MAXN=2e5+1;
const int M=998244353;
 
ll dp[3001][3001],arr[3001]; 


void solve(){
	int n,s;
	sfi(n) sfi(s)

	f(i,1,n+1){
		sfl(arr[i])
	}

	dp[0][0]=1;

	ll ans=0;

	for(int i=1;i<=n;i++){
		for(ll sum=0;sum<=s;++sum){
			dp[i][sum]=dp[i-1][sum];

			if(sum>=arr[i]){
				dp[i][sum]+=dp[i-1][sum-arr[i]];
				dp[i][sum]%=M;
			}

			//dp[i][arr[i]]+=(i);
			dp[i][arr[i]]%=M;
		}

		dp[i][arr[i]]+=(i-1);
	//	cout<<dp[i][s]<<endl;
		ans=(ans+dp[i][s])%M;
	}

	pfln(ans)

}


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

Measured memory_bytes: 70656
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int int_vector_find(std::vector<int> vec, int num) {
	auto itr = std::find(vec.begin(), vec.end(), num);
	int index = std::distance(vec.begin(), itr);

	if (index != vec.size()) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {
	std::string str;
	std::cin >> str;
	int ans = 0;
	int temp = 0;

	for (int i = 0; i < str.size(); ++i) {
		if (str[i] == 'A' || str[i] == 'T' || str[i] == 'G' || str[i] == 'C') {
			temp++;
		}
		else {
			temp = 0;
		}
		if (temp > ans) {
			ans = temp;
		}
	}

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

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

int main() {
  char s[100001];
  int arr[26]={}, i;
  cin >> s;

  for (i=0; s[i]!='\0'; i++) {
    arr[s[i]-'a']++;
  }

  for (i=0; i<26; i++) {
    if (arr[i]==0) {
      printf("%c\n", i+'a');
      return 0;
    }
  }

  printf("None\n");
  return 0;
}

Measured memory_bytes: 384
import math
import bisect
from queue import Queue
from collections import deque

n = int(input())
table = [[int(i) for i in input().split()] for j in range(n)]

d = [[0 for _ in range(3)] for _ in range(n)]


for i in range(n):
    if(i == 0):
        for j in range(3):
            d[i][j] = table[i][j]
    else:
        d[i][0] = table[i][0] + max(d[i-1][1], d[i-1][2])
        d[i][1] = table[i][1] + max(d[i-1][0], d[i-1][2])
        d[i][2] = table[i][2] + max(d[i-1][0], d[i-1][1])
print(max(d[n-1]))

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

using namespace std;

typedef long long ll;

const int Inf = 1e9;

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

    vector <int> a(n);
    vector <int> b(n);

    for(int i = 0; i < n; i++)  scanf("%d%d", &a[i], &b[i]);

    vector <int> Dp(m + 1, Inf);

    Dp[0] = 0;

    for(int i = 0; i < n; i++)
        for(int j = 0; j <= m; j++)
            Dp[j] = min(Dp[j], b[i] + (j < a[i] ? 0 : Dp[j - a[i]]));

    cout << Dp[m] << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	int a[2][n];
	rep(i,2) rep(j,n) cin >> a[i][j];

	int ans = 0;
	rep(i,n){
		int sm = 0;
		rep(j,i+1) sm += a[0][j];
		FOR(j,i,n) sm += a[1][j];
		ans = max(ans, sm);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    x, y = (int(i) for i in input().split())
    if x ==0 and y == 0:
        break
    else:
        s = "#"
        line =  s * y
        print(line)
        for i in range(x-2):
            print("#"+"."*(y - 2)+"#")
        print(line)
        print()        

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
string s;
cin>>s;
int x=0;
int max_val=0;
rep(i,n){
    if(s[i]=='I'){
        x++;
    }
    else{
        x--;
    }
    max_val=max(max_val,x);
}
cout<<max_val<<endl;
return 0;
}

Measured memory_bytes: 256