akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ull unsigned long long
#define ld long double
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;

using namespace std;

const int N = 4e3 + 123;

int n , k , a[4000] ;
bool was[N][N] ;
int dp[N][N];
int get(int l , int r){
	if(l == r)
		return a[l];
	if(r - l == 1){
		return max(a[l] , a[r]);
	}
	if(was[l][r])
		return dp[l][r];
	int tmp1 = a[l] + min(get(l + 1 , r - 1) , get(l + 2 , r));
	int tmp2 = a[r] + min(get(l + 1 , r - 1) , get(l , r - 2));
	
	was[l][r] = 1;
	dp[l][r] = max(tmp1 , tmp2);
	return dp[l][r];
}
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin >> n;
	int sum = 0;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];
		sum += a[i];
	}
	int tmp = get(1 , n);
	cout << tmp - (sum - tmp);
}

Measured memory_bytes: 112768
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { //Partition babyyyyyyyyy
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String S = I.next();
		int N = S.length();
		int[] dig = new int[N];
		int ans = 0;
		for (int i = 0; i < N; i++) {
			dig[i] = Integer.parseInt(S.substring(i,i+1));
			ans+=dig[i];
		}
		//Optimize
		for (int upd = 0; upd<N; upd++) {
			int cursum = 0;
			for (int prev = 0; prev<upd;prev++) {
				cursum+=dig[prev];
			}
			cursum+=dig[upd]-1; //Decrement current
			cursum+=(N-upd-1)*9; //-1 to convert to 1 based indexing
			ans=Math.max(ans, cursum);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 25472
#include <bits/stdc++.h>
#define ll long long
#define qomzi(n,i) for(register int i=1;i<=(n);++i)
#define INF 1e9

using namespace std;
inline int icin(){
	char c=getchar();int s=0;bool sign=0;
	while(!isdigit(c)&&c^'-')c=getchar();
	if(c=='-')c=getchar(),sign=1;
	while(isdigit(c))s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return sign?-s:s;
}

int N,Res=0,tot=0;
char s;
int main(){
	N=icin();
	while(N--){
		s=getchar();
		if(s=='I') Res=max(Res,++tot);
		if(s=='D') tot--;
	}
	printf("%d\n",Res);	
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ull<<62)-1)
#define cINFINT ((1<<30)-1)


int main()
{
	string s; cin >> s;
	ll k = s.length();
	ll w = 0;
	REP(i,k) if(s[i]=='o') ++w;
	cout << (w+(15-k)>=8? "YES": "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, a[102] = {}, b, c, d = 0;
    cin >> n >> k;
    for (int i = 1; i <= k; i++) {
        cin >> b;
        while (b--) cin >> c, a[c] = 1;
    }
    for (int i = 1; i <= n; i++) if (!a[i]) d++;
    cout << d;
}


Measured memory_bytes: 3620
// vector の添字と読み込んだ順番を勘違いしていた
// map とか使って若干高速化．．
#include<vector>
#include<map>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

void print(vector<li> vec,string str=""){
  if(not (str=="")) cout << str << ":";
  for(auto x:vec) printf("%ld ",x);
  printf("\n");
}

void print(map<int,int> mp,string str=""){
  if(not (str=="")) cout << str << ":";
  for(auto x:mp) printf("(%d,%d)",x.first,x.second);
  printf("\n");
}
void print(vector<pair<int,int>> mp,string str=""){
  if(not (str=="")) cout << str << ":";
  for(auto x:mp) printf("(%d,%d)",x.first,x.second);
  printf("\n");
}
void print(  map<int,pair<int,int>> mp,string str=""){
  if(not (str=="")) cout << str << ":";
  for(auto x:mp) printf("(%d,%d,%d)",x.first,x.second.first,x.second.second);
  printf("\n");
}


int main(){
  if(df) printf("*debug mode*\n");
  int n;cin >> n;
  int M=0;
  map<int,pair<int,int>> dict;
  dict[0]=make_pair(0,0);
  vector<li> mul(1,0),rem(1,0);
  int cnt=1;
  rep(i,n){
    int a; cin >>a;
    if(df){printf("read:%d ,%d ",a,M); cout << endl;}
    if(a>M){
      M=a;
      dict[a]=make_pair(i+1,cnt++);
      mul.push_back(1);
      rem.push_back(0);
      if(df)printf("add %d\n",i+1);
    } else if(a==M){
      auto& x=*(mul.rbegin());
      x++;
    } else {
      auto itr=dict.upper_bound(a);
      if(itr==dict.begin())return 0;
      auto x=*(--itr);
      if(df){
	printf("itr:%d  %d",x.second.first,x.second.second);
	cout <<endl;
      }
      mul.at(x.second.second)++;
      rem.at(x.second.second+1)+=a-x.first;
      if(df)printf("mul%d:+1, rem%d:+%d\n",x.second.second,x.second.second+1,a-x.first);
    }
    if(df){
      print(dict,"dict");
      print(mul,"mul");
      print(rem,"rem");
    }
  }
  
  if(df)printf("a");// cout  <<endl;
  for(int i=mul.size()-2;i>0;i--){
    mul.at(i)+=mul.at(i+1);
  }
  if(df){
    print(mul,"mul");
    print(rem,"rem");
  }
  vector<pair<int,int>> dictv;
  for(auto x:dict){
    dictv.push_back(make_pair(x.first,x.second.first));
  }
  auto itr=dict.begin();
  repa(i,1,mul.size()){
    rem.at(i)+=(dictv.at(i).first-dictv.at(i-1).first)*mul.at(i);
  }
  if(df){
    print(dictv);
    print(mul,"mul");
    print(rem,"rem");
  }
  dictv.push_back(make_pair(n+1,n+1));
  int k=1;
  repa(i,1,n+1){
    if(df)printf("k%di%d ",k,i);
    if(dictv.at(k).second==i){
      printf("%ld\n",rem.at(k));
      k++;
    }else{
      printf("0\n");
    }
  }

  if(df)printf("done\n");
}

/// confirm df==0 ///


Measured memory_bytes: 9704
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k;
  cin >>n >>k;
  string s;
  cin >>s;
  long long int cuts[n],cute[n];
  long long int j=-1,kk=-1;
  if(s[0]=='1'){
    j++;
      cuts[0]=0;
    }
  if(s[0]=='0'){
    j++;
    cuts[0]=0;
    kk++;
    cute[0]=0;
  }
  for(int i=0;i<s.size()-1;i++){
    if(s[i]!=s[i+1] && s[i]=='0'){
      j++;
      cuts[j]=i+1;
    }
    if(s[i]!=s[i+1] && s[i]=='1'){
      kk++;
      cute[kk]=i+1;
    }
  }
  if(s[s.size()-1]=='1'){
    kk++;
      cute[kk]=s.size();
    }
  if(s[s.size()-1]=='0'){
    j++;
    cuts[j]=s.size();
    kk++;
    cute[kk]=s.size();
  }
  long long int ans=0;
  for(int i=0;i<j+1;i++){
        ans=max(ans,cute[min(i+k,kk)]-cuts[i]);

   }
    cout << ans<<endl;
  
}


Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

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


void solve() {
	int n; cin >> n;
	vector<int> p(n);
	rep(i, n) {
		cin >> p[i];
	}
	int ans = 0;
	int mi = mod;
	rep(i, n) {
		mi = min(mi, p[i]);
		if (mi >= p[i])ans++;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}

Measured memory_bytes: 1024
# from math import factorial,sqrt,ceil
# from itertools import permutations as permus
from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
a,b,k = map(int,input().split())

def makedivs(n):
    divs = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    # divs.sort()
    return divs

c = gcd(a,b)
anslis = makedivs(c)
anslis.sort()

print(anslis[-k])
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

int lengthOfLcs_r(const char x[], const char y[], int ix, int iy, int xsize, int ysize, int **lengthTable) {
	if (ix == xsize || iy == ysize) {
		return 0;
	}
	if (lengthTable[ix][iy] != -1) {
		return lengthTable[ix][iy];
	}
	if (x[ix] == y[iy]) {
		return lengthTable[ix][iy] = lengthOfLcs_r(x, y, ix + 1, iy + 1, xsize, ysize, lengthTable) + 1;
	}
	return lengthTable[ix][iy] = max(lengthOfLcs_r(x, y, ix, iy + 1, xsize, ysize, lengthTable), lengthOfLcs_r(x, y, ix + 1, iy, xsize, ysize, lengthTable));
}

int lengthOfLcs(string x, string y) {
	int xsize = x.size(), ysize = y.size();

	int **lengthTable = new int*[xsize];
	for (int i = 0; i < xsize; ++i) {
		lengthTable[i] = new int[ysize];
		fill_n(lengthTable[i], ysize, -1);
	}

	int ret = lengthOfLcs_r(x.c_str(), y.c_str(), 0, 0, xsize, ysize, lengthTable);
	
	for (int i = 0; i < xsize; i++) {
		delete[] lengthTable[i];
	}
	delete[] lengthTable;
	
	return ret;
}

int main() {
	int q;
	string x, y;

	cin >> q;
	for (int i = 0; i < q; ++i) {
		cin >> x >> y;
		cout << lengthOfLcs(x, y) << endl;
	}
	return 0;
}


Measured memory_bytes: 7056
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = 1e9 + 7;

ll a[200001] = {};

int main() {
	ll n; cin >> n;
	rep(i, 0, n) {
		ll p; cin >> p;
		a[i] = (p - i - 1);
	}

	sort(a, a + n);
	ll b = a[n / 2];

	ll ans = 0;
	rep(i, 0, n) ans += abs(a[i] - b);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
vector < int > v;
map < int, int > mp;

int main()
{

    bool vis[110];
    int M,k;
    cin >> M >> k;
    int Xor = 0;
    for(int i = 0; i<(1 << M); i++)
    {
        v.push_back(i);
        v.push_back(i);
        if(i != k)  Xor^=i;
    }
    if(k == 0){
        for(auto it : v)  cout << it << " ";
        return 0;
    }
    if(Xor == k){
        int n = (1 << (M + 1));
        v[n/2 - 1] = k;
        int j = 0;
        for(int i = 0;i<n/2 - 1;i++){
            if(j == k)  j++;
            v[i] = j;
            v[n - 2 - i] = j;
            j++;
        }
        v[n - 1] = k;
        for(auto it : v)  cout << it << " ";
        return 0;
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 2932
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int A[101],B[101];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),o=0;
	for(int i=1;i<=m;++i)A[i]=gi();
	if(n==1)return printf("1\n1\n1\n"),0;
	if(m==1)printf("%d\n2\n%d 1\n",A[1],A[1]-1);
	else{
		for(int i=1;i<=m;++i)
			if(A[i]&1){
				++o;
				if(o==1)std::swap(A[i],A[1]);
				else if(i<m&&(A[m]&1))o=10000000;
				else std::swap(A[i],A[m]),o-=i<m;
			}
		if(o>2)return puts("Impossible"),0;
		for(int i=1;i<=m;++i)printf("%d ",A[i]);
		puts("");
		printf("%d\n",m-(A[m]==1));
		printf("%d ",A[1]+1);
		for(int i=2;i<=m;++i)if(i<m||A[i]>1)printf("%d ",A[i]-(i==m));
	}
	return 0;
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

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

    vector<double> p(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }

    vector<vector<double>> dp(n + 1, vector<double>(n + 1));
    dp[1][0] = 1 - p[1];
    dp[1][1] = p[1];

    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j > 0) {
                dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
            } else {
                dp[i][j] = dp[i - 1][j] * (1 - p[i]);
            }
        }
    }

    double t = 0;
    for (int j = n / 2 + 1; j <= n; j++) {
        t += dp[n][j];
    }

    cout << fixed << setprecision(10) << t << endl;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    multiset<ll> st;
    REP(i, n) st.insert(a[i]);

    ll t = 2;
    vector<ll> p;
    while(t < (1LL<<31)) {
        p.push_back(t);
        t *= 2;
    }

    ll ret = 0;
    while(st.size()>=2) {
        ll x = *st.rbegin();
        st.erase(st.find(x));
        REP(i, p.size()) {
            auto itr = st.find(p[i]-x);
            if(itr == st.end()) continue;

            ret++;
            st.erase(itr);
            break;
        }
    }

    cout << ret << endl;

    return 0;
}

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

int operation(int x , int y , int z)
{
    int v = (x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(x*z);
    return v;
}
int main()
{
    int n;
    cin >>n;
    int counter=0;
    for(int i =1; i<=n; i++)
    {
        for(int x=1; x<100; x++)
        {
            for(int y=1; y<100; y++)
            {
                for(int z=1; z<100; z++)
                {
                    if(i == operation(x,y,z))
                    {
                        counter++;
                    }
                    else if(i < operation(x,y,z))
                        break;

                }
            }
        }

        cout<<counter<<endl;
        counter=0;
    }

    return 0;
}

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

int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  vector<int> time(5);
  time = {a, b, c, d, e};
  vector<int> index;
  index = {0, 1, 2, 3, 4};
  int ans = 1000000000;
  do {
    int now = 0;
    for(int i = 0; i < 5; i++) {
      while (now % 10 != 0) now++;
      now += time.at(index.at(i));
    }
    ans = min(ans, now);
  }while (next_permutation(index.begin(), index.end()));
  cout << ans << endl;
  return 0;
}

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

int main() {
  ll x;cin>>x;
  ll ure=0;
  ure += (x/500)*1000;
  x %= 500;
  ure += (x / 5)*5;
  cout << ure;
}


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

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

vector <pll> V[101010];
ll S[101010], dp[101010][3];
ll n;

void dfs(ll p, ll r)
{
	ll s0, s1f, s1s, s2;
	ll k0, k1, k2;
	
	S[p] = 1;
	s0 = 0;
	s1f = s1s = s2 = -1e16;
	
	for(pll t: V[p]){
		if(t.first != r){
			dfs(t.first, p);
			S[p] += S[t.first];
			k0 = dp[t.first][0] + t.second * (min(S[t.first], (n - S[t.first]) - 1) * 2);
			k1 = dp[t.first][1] + t.second * (min(S[t.first], (n - S[t.first])) * 2 - 1);
			k2 = dp[t.first][2] + t.second * (min(S[t.first] - 1, (n - S[t.first])) * 2);
			s0 += k0;
			if(s1f < k1 - k0) s1s = s1f, s1f = k1 - k0;
			else if(s1s < k1 - k0) s1s = k1 - k0;
			s2 = max(s2, k2 - k0);
		}
	}
	
	dp[p][0] = s0;
	dp[p][1] = max(s0, s0 + s1f);
	dp[p][2] = max(max(s0 + s2, s0 + s1f + s1s), s0 + s1f);
}

int main()
{
	ll i, a, b, c;
	
	scanf("%lld", &n);
	
	for(i=1;i<n;i++){
		scanf("%lld%lld%lld", &a, &b, &c);
		V[a].push_back(pll(b, c));
		V[b].push_back(pll(a, c));
	}
	
	dfs(1, 0);
	
	printf("%lld\n", dp[1][2]);
	
	return 0;
}

Measured memory_bytes: 19072
N,K = map(int, input().split())
p = list(map(int, input().split()))

max=0
tmp=0
for x in range(0,K):
    max+=p[x]
    tmp+=p[x]
for i in range(K,N):
    tmp=tmp+p[i]-p[i-K]
    if tmp>max:
        max=tmp
print((max+K)*0.5)

Measured memory_bytes: 71792
/*input
15 6
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=5e3+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
ll inv(ll z){
    if(z==1) return 1;
    return (MOD-MOD/z)*inv(MOD%z)%MOD;
}
ll c(ll n,ll k){
    ll z=1;
    for(ll i=n-k+1;i<=n;i++) z=(z*i)%MOD;
    ll b=1;
    for(ll i=1;i<=k;i++) b=(b*i)%MOD;
    return z*inv(b)%MOD;
}
int main(){
    ll n,k;
    cin>>n>>k;
    MNTO(k,n);
    ll ans=0;
    ll curn=1,cure=1;
    REP(i,k+1){

        ans+=mult(curn,cure);
        ans%=MOD;
        curn=mult(mult(curn,(n-i)),inv(i+1));
        cure=mult(mult(cure,(n-i-1)),inv(i+1));
        curn%=MOD;
        cure%=MOD;
    }
    cout<<ans;
   // cout<<c(n+2*k,n+k)<<'\n';
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1
#define TRUE 2
#define FALSE 0

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int X[N][N];

void initialize(void);
void printboard(void);
void recursive(int);

int main(){
  int i,j,k,r,c;

  initialize();

  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      X[i][j] = FALSE;

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

  recursive(0);

  return 0;
}

void initialize(){
  int i;

  for(i=0;i<N;i++){
    row[i] = FREE;
    col[i] = FREE;
  }

  for(i=0;i<2*N-1;i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

void printboard(){
  int i,j;

  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      if(X[i][j] == TRUE){
        if(row[i] != j)return;
      }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;

  if(i == N){
    printboard();
    return;
  }

  for(j=0;j<N;j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE) continue;
    row[i] =j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    recursive(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

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

int main(){
    string s;
    cin >> s;
    int min = 10000;
    for(int i=0;s[i] != '\0';i++){
        int diff = abs(753 - stoi(s.substr(i,3))); 
        if (diff < min) min = diff;
    }
    cout << min << endl;
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}



int main() {


	int n;
	cin >> n;
	string s;
	cin >> s;
	VLL a(3, 0);
	VLL b(3, 0);
	REP(i, n) {
		if (s[i] == 'R') {
			b[0]++;
		}
		else if (s[i] == 'G') {
			b[1]++;
		}
		else {
			b[2]++;
		}
	}


	ll ans = 0;

	REP(i, n) {
		if (s[i] == 'R') {
			b[0]--;
			ans += a[1] * b[2] + a[2] * b[1];
			a[0]++;
		}
		else if (s[i] == 'G') {
			b[1]--;
			ans += a[0] * b[2] + a[2] * b[0];
			a[1]++;
		}
		else {
			b[2]--;
			ans += a[0] * b[1] + a[1] * b[0];
			a[2]++;
		}
	}
	REP(j, n) {
		REP(i, j) {
			int k = j * 2 - i;
			if (k >= n)continue;
			if (k <= j)continue;
			if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) {
				ans--;
			}
		}
	}

	cout << ans << endl;


}

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

int main()
{
  int l;

  while (cin >> l && l != 0){
    int m, n, a = 0;
    for (int i = 1; i <= 12; i++){
      cin >> m >> n;
      l = l - m + n;
      if (l > 0){
        a = i;
      }
    }
    if (a == 12){
      cout << "NA" << endl; 
      continue;
    }
    cout << a + 1 << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
 
using namespace std;

int i,j,k;
 
int max(int a, int b)
{
    if(a>b) return a;
    else return b;
}
 
int min(int a,int b)
{
    if(a<b) return a;
    else return b;
}

int fast_power(int a,int b)
{
    int res=1;
    while(b>0)
    {
        if(b%2==0)
        {
            b/=2;
            a=(a*a)%mod;
        }
        else
        {
             b/=2;
             res=(res*a)%mod;
            a=(a*a)%mod;
        }
    }
    return res;
}

signed main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    n=n%k;
    n=min(n,abs(n-k));
    cout<<n;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
i = 0
ans = 0
while i != n:
    if p[i] == i + 1:
        cnt = 0
        while i + cnt != n and p[i + cnt] == i + cnt + 1:
            cnt += 1
        ans += cnt//2 + cnt%2
        i += cnt
    else:
        i += 1
print(ans)

Measured memory_bytes: 83940
<?php
// https://atcoder.jp/contests/abc144/tasks/abc043_a
// 一人目には1個、二人目には2個、3人目には3個のアメをプレゼントする。
// 必要なアメの数はいくつ？


// fgets(STDIN)で標準入力,trimで改行を削除
$N = trim(fgets(STDIN));

//解答用のcountを定義
$count = 0;

//定数Nまでcountに足し合わせる
for($i = 0; $i <= $N; $i++){
  $count += $i;
}

//答えを出力
echo $count."\n";

Measured memory_bytes: 4604
X = int(input())

if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)
elif 1800 <= X <= 1999:
    print(1)


Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        }else if(a>b){
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
        }
    }
}



Measured memory_bytes: 26360
using System;
 
class Program
{
    static void dfs(int y, int x, bool[,] map)
    {//             ??? ???  ???  ???
        int[] dx = { 1, 0, -1, 0 };
        int[] dy = { 0, 1, 0, -1 };
 
        map[y, x] = false;
 
        for (int i = 0; i < 4; i++)
        {
            int nx = x + dx[i];
            int ny = y + dy[i];
 
            if (nx >= 0 && nx < 12 && ny >= 0 && ny < 12 && map[ny, nx])
            {
                dfs(ny, nx, map);
            }
        }
    }
 
 
 
 
    static void Main()
    {
        while (true)
        {
            string input;
            bool[,] map = new bool[12, 12];
            int count = 0;
 
            for (int y = 0; y < 12; y++)
            {
                input = Console.ReadLine();
 
                for (int x = 0; x < 12; x++)
                {
                    if (input[x] == '1') map[y, x] = true;
                }
            }
 
            for (int y = 0; y < 12; y++)
            {
                for (int x = 0; x < 12; x++)
                {
                    if (map[y, x] == true)
                    {
                        dfs(y, x, map);
                        count++;
                    }
                }
            }
 
            Console.WriteLine(count);
            
            if ((input = Console.ReadLine()) == null) break;
        }
    }
}

Measured memory_bytes: 8860
#include <stdio.h>
int power(int b,int p){
	int a=1,i;
	for(i=1; i<=p; i++){
		a=a*b;
	}
	return a;
}
int main(void)
{
	int x,y,b,p,max=0;
	scanf("%d",&x);
	for(b=1; b<=32; b++){
		for(p=2; p<=10; p++){
			y=power(b,p);
			if(y>x){
				break;
			}
			if(max<y){
				max=y;
			}
		}
	}
	printf("%d\n",max);
	return 0;
}

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



int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i, n) cin >> v[i];
  sort(all(v));
  double ans = v[0];
  for (int i = 1; i < n; i++) {
    ans = ans/2 + v[i]/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),i;
		long a,t[]=new long[200000],m=Long.MAX_VALUE;
		for(i=0;i<n;i++) {
			a=sc.nextInt();
			t[i]=a;
			if(0<i) t[i]+=t[i-1];
		}
		sc.close();
		for(i=0;i<n-1;i++) if(m>Math.abs(2*t[i]-t[n-1])) m=Math.abs(2*t[i]-t[n-1]);
		System.out.print(m);
	}
}

Measured memory_bytes: 79576
import sys
import math

A,B,C,D = map(int, input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


maru1 = B // C
maru2 = (A-1) // C

maru3 = B // D
maru4 = (A-1) // D

maru5 = B // lcm(C,D)
maru6 = (A-1) // lcm(C,D)

ans_tmp = ((maru1-maru2)+(maru3-maru4)) - (maru5-maru6)
ans = (B-A+1) - ans_tmp

print(ans)

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

int main() {
    int N,K;
    cin >> N >> K;
    
    int t=0;
    double p=0;
    for(int D=1;D<(N+1);D++){
    	if(K<=D) p+=1;
    	else p+=1.0/pow(2,ceil(log2(K/(double)D)));
    }
    p = p/N;

    

    printf("%.10f\n",p);


}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)
const MAX_WIDTH = 1500000

func main() {
	// 二分探索で探す
	// 二分探索はソート済みの配列に対して、特定の条件を満たす値を
	// 効率よく選択するアルゴリズム
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		m, _ := strconv.Atoi(buf[0])
		n, _ := strconv.Atoi(buf[1])
		if n == 0 && m == 0 {
			break
		}
		books := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			books[i], _ = strconv.Atoi(scanner.Text())
		}
		check := func(width int) bool {
			// widthの幅の本棚に順番にbooksを詰めて行ったら
			// 何段になるのかを確認し、それがmを以下であることを確認する
			shelf_index := 1
			position_in_stage := 0
			for i := 0; i < n; i++ {
				// 入れることができない本がある時点でこのwidthは不採用
				if books[i] > width {
					return false
				}
				// 新たに本を追加することができるかをチェックする
				if position_in_stage + books[i] <= width {
					// 新たに本を入れることができたので、そのステージにおける
					// 現在の本の位置を記録
					position_in_stage += books[i]
				} else {
					// 新たな本を入れることができなかったので、一段下のステージに
					// 入れれば良い
					position_in_stage = books[i]
					shelf_index++ // 本棚のステージ数が増えた
				}
			}
			return shelf_index <= m // 条件を満たすかの確認
		}
		low, high := 0, MAX_WIDTH
		for low < high {
			mid := (low+high)/2
			if check(mid) {
				high = mid
			} else {
				low = mid+1
			}
			// log.Printf("low: %d, high: %d\n", low, high)
		}
		fmt.Println(low)
	}
}


Measured memory_bytes: 1108
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		// 計算
		int result = 0;
		if(a == b) result = c;
		if(b == c) result = a;
		if(c == a) result = b;
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int E = s.nextInt();
		int Y = s.nextInt();
		
		if (E == 0){
			if (Y <= 1911){
				System.out.print("M");
				System.out.println(Y - 1867);
			}else if(Y <= 1925){
				System.out.print("T");
				System.out.println(Y - 1911);
			}else if(Y <= 1988){
				System.out.print("S");
				System.out.println(Y - 1925);
			}else{
				System.out.print("H");
				System.out.println(Y - 1988);
			}
		} else if(E == 1){
			System.out.println(1867 + Y);
		}else if(E == 2){
			System.out.println(1911 + Y);
		}else if(E == 3){
			System.out.println(1925 + Y);
		}else{
			System.out.println(1988 + Y);
		}
	}
}

Measured memory_bytes: 26320
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(0,min(b,d)-max(a,c));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int X;
    cin >> X;
    if(X == 7 || X == 5 || X == 3)
        cout << "YES" << endl;
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
using namespace std;
int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<int> > map(H,vector<int>(W));
    REP(i,H){
        REP(j,W){
            cin >> map[i][j];
        }
    }
    long long ans = 0;
    REP(i,H){
        REP(j,W){
            ans += (long long)map[i][j] * (i+1) * (H-i) * (j+1) * (W-j);
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
	ll ans,n,c;
	cin >> n;
	vector <ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	ans=0;
	sort(a.begin(),a.end());
	// for(int i=0;i<n;i++){
	// 	cout << a[i] << endl;
	// }
	for(int i=0;i<n-1;i++){
		if(a[i]<=0 && a[i+1]<=0){
			a[i]=-a[i];
			a[i+1]=-a[i+1];
			}
		else if(a[i]<=0 && a[i+1]>=0){
			if(-a[i]>=a[i+1]){
				a[i] = -a[i];
				a[i+1] = -a[i+1];
			}
		}

	}
	for(int i=0;i<n;i++){
		ans += a[i];
	}
	cout << ans;
	cin >> n;
}



Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
    int a;

    scanf("%d", &a);
    if(a % 10 == 9 ) printf("Yes");
    else if(90 <= a && a < 99) printf("Yes");
    else printf("No");

    // int i, N;

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

}




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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    ll n; cin >> n;

    ll ans = 1;

    for (ll i = 1; i <= n; ++i) {
        ans *= i;
        ans = ans % 1000000007;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
class Program{
	public static void Main(){
		string[] str = Console.ReadLine().Split(' ');
		int a = int.Parse(str[0]);
		int b = int.Parse(str[1]);
		if (a % 2 == 0)
			Console.WriteLine("Even");
		else if (b % 2 == 0)
			Console.WriteLine("Even");
		else
			Console.WriteLine("Odd");
	}
}

Measured memory_bytes: 11092
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
//#include "Header.h"
int main()
{
	int a, b, c, d, e, i, j, ans = 0, l = 0;
	cin >> a >> b >> c >> d >> e;
	if (a % 10) ans += (a / 10 + 1) * 10, l = max(l, 10 - a%10);
	else ans += a;
	if (b % 10) ans += (b / 10 + 1) * 10, l = max(l, 10 -  b%10);
	else ans += b;
	if (c % 10) ans += (c / 10 + 1) * 10, l = max(l, 10 - c%10);
	else ans += c;
	if (d % 10) ans += (d / 10 + 1) * 10, l = max(l, 10 - d%10);
	else ans += d;
	if (e % 10) ans += (e / 10 + 1) * 10, l = max(l, 10 - e%10);
	else ans += e;
	cout << ans - l << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    a, b = map(int, input().split())
    s.append(a)
    c.append(b)
val = 10**n
if n == 1 and m == 0:
    print(0)
else:
    for i in range(10**(n-1), val):
        flag = True
        for j in range(m):
            if str(i)[s[j]-1] == str(c[j]):
                pass
            else:
                flag = False
                break
        if flag:
            print(i)
            break
    if flag:
        pass
    elif n == 1 and m == 1 and s[0] == 1 and c[0] == 0:
        print(0)
    else:
        print(-1)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;

int main() {

int N;
int A[100];
int ans=0;

cin>>N;

fx(N){
	cin>>A[x];
	ans+=A[x];
}

if(ans%10!=0){
	ce(ans);	
}else{
	sort(A,A+N);
	int i=0;
	while(A[i]%10==0&&i<N){i++;}
	if(i!=N){
	ce(ans-A[i]);
	}else{
		ce("0");
	}
}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<long long>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;


void func()
{ 
  ll h1,m1,h2,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  ll t1=h1*60+m1;
  ll t2=h2*60+m2;

  if(t1<=t2)
  {
    ll ans=0;
    if(t1<=t2-k) ans=t2-k-t1;
    pr(ans) nl
  }

  else
  {
    ll ans=0;
    ll pp=24*60;
    t2=(t2-k+pp)%pp;
    ans=max((ll)0,t2-t1);
    pr(ans) nl
  }
}   
     
     
int main() 
{
    //fast
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }     
    return 0;
}

Measured memory_bytes: 3624
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
for a in A:
    if a % 2 == 0 and (a % 3 != 0 and a % 5 != 0) : 
        print('DENIED')
        sys.exit()
print('APPROVED')

Measured memory_bytes: 9176
n = int(input())
R = list()

for i in range(n):
    R.append(int(input()))

minimum = R[0]
sa = R[1] - R[0]

for i in range(1, n):
    if minimum > R[i-1]:
        minimum = R[i-1]

    if sa < R[i] - minimum:
        sa = R[i] - minimum

print(sa)


Measured memory_bytes: 13584
import itertools
H,W,K = map(int, input().split())

matrix =[]
rowblack = []

for i in range(H):
    row = list(input())
    matrix.append(row)
    rowblack.append(row.count('#'))

allblacks = sum(rowblack)
ans = 0

selectRows = list(itertools.product([0,1], repeat=H))
selectColumns = list(itertools.product([0,1], repeat=W))

for selectRow in selectRows:
    for selectColumn in selectColumns:
        counter = 0

        for row in range(H):
            for column in range(W):
                if selectRow[row] == 0 and selectColumn[column] == 0 and matrix[row][column] == '#':
                    counter += 1
        
        if counter == K:
            ans += 1

print(ans)

Measured memory_bytes: 9132
import sys

import numba as nb

input = sys.stdin.readline


@nb.njit
def solve(n):
    table = [0] * (n + 1)
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    ans = 0
    for i, v in enumerate(table):
        ans += i * v
    return ans


def main():
    N = int(input())

    ans = solve(N)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 189048
n, y = map(int, input().split())
a = 0
a += (y%5000)//1000
n -= a
y -= a*1000
if n*10000>=y and y>=n*1000:
  if y>= 5000*n:
    m = (y-5000*n)//5000
    print(m,n-m,a)
  else:
    m = y-1000*n+9000
    for i in range(n):
      m -= 9000
      if m < 0:
        print(-1,-1,-1)
        exit(0)
      if m%4000 == 0:
        j = m//4000
        print(i,j,n-i-j+a)
        exit(0)       
else:
  print(-1,-1,-1)

Measured memory_bytes: 3064
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()))

def main():
    mod=10**9+7
    N=I()
    a=LI()
    L=[0]*8
    F=0
    for i in range(N):
        if a[i]>=3200:
            F+=1
            continue
        b=a[i]//400
        L[b]=1
        
    ans=sum(L)
    aaa=0
    if min(a)>=3200:
        aaa+=1
    print(ans+aaa,ans+F)
        

main()


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

using namespace std;
typedef long long ll;

int main(void) {
  int n;
  string s;
  cin >> n >> s;

  vector<ll> cumj(n, 0), cumi(n, 0);
  for (int i = 0; i < n; i++) {
    cumj[i] = s[i] == 'J';
    cumi[i] = s[i] == 'I';
  }
  for (int i = 1; i < n; i++) {
    cumj[i] += cumj[i - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    cumi[i] += cumi[i + 1];
  }

  ll cntj = 0, cnto = 0, cnti = 0, maxo = 0;
  for (int i = 0; i < n; i++) {
    maxo = max(maxo, cumj[i] * cumi[i]);
    if (s[i] != 'O') continue;
    cntj += (cumj[i] + 1) * cumi[i];
    cnto += cumj[i] * cumi[i];
    cnti += cumj[i] * (cumi[i] + 1);
  }

  cout << max(cntj, max(cnto + maxo, cnti)) << endl;

  return 0;
}


Measured memory_bytes: 4796
use std::str::FromStr;
use std::io::stdin;
use std::collections::binary_heap::BinaryHeap;
use std::cmp::max;

fn main() {
    let (x, y) = {
        let line = read_vec::<u64>();
        (line[0], line[1])
    };
    let mut queue = BinaryHeap::new();
    queue.push(x);
    queue.push(y);
    let mut result = 0 as u64;
    for _ in 0..2 {
        let v = queue.pop().unwrap();
        result += v;
        queue.push(max(0, result - 1));
    }
    println!("{}", result);
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

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

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(lambda x : int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)

mod = 10**9+7
fact = [1] * N
fact_inv = [1] * N
inv = lambda x : pow(x, mod-2, mod)
for i in range(1, N):
    fact[i] = i * fact[i-1] % mod
    fact_inv[i] = inv(fact[i])
comb = lambda n, k : fact[n] * fact_inv[k] * fact_inv[n-k] % mod

value = [1] * N
count = [0] * N
def dfs(par, v):
    for u in G[v]:
        if par == u:
            continue
        dfs(v, u)
        count[v] += count[u]
        value[v] = value[v] * value[u] * comb(count[v], count[u]) % mod
    count[v] += 1

ans = [0] * N
def reroot(par, val_par, cnt_par, v):
    ans[v] = val_par * value[v] * comb(N-1, cnt_par) % mod
    for u in G[v]:
        if par == u:
            continue
        val = ans[v] * inv(value[u] * comb(N-1, count[u])) % mod
        reroot(v, val, N-count[u],  u)

dfs(-1, 0)
reroot(-1, 1, 0, 0)
print(*ans, sep='\n')

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

typedef long long ll;
ll MOD = 1000000007;

int main()
{
    int N, L, sum = 0, tmp = 1e9;
    cin >> N >> L;

    for (int i = L; i <= L + N - 1; i++) {
        //cout << i << endl;
        sum += i;
        if (abs(tmp) > abs(i)) tmp = i;
    }
    cout << sum - tmp << endl;
    return 0;
}


Measured memory_bytes: 256
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
   "math"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  //r := float64(nextInt())
  r := nextFloat()
  area := r * r * math.Pi
  d := 2 * r * math.Pi 
  fmt.Println(strconv.FormatFloat(area, 'f', 6, 64) +" " + strconv.FormatFloat(d, 'f', 6, 64))
} 


func nextInt() (int) {
    sc.Scan()
    v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}   

func nextFloat() (float64) {
    sc.Scan()
    v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}


Measured memory_bytes: 1116