akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>

using namespace std;
using lint = int64_t;
using P = pair<lint, lint>;

#define rep(i, n) for (lint i = 0; i < (n); ++i)
#define rep1(i, n) for (lint i = 1; i < (n); ++i)
#define repn(i, a, b) for(lint i = (a); i < (b); ++i)
#define Rep(i, n) for (lint i = (n); i >= 0; --i)
#define All(vec) vec.begin(), vec.end()
#define cend printf("\n")

//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1000'000'007LL;
constexpr lint inf = 3LL * mod * mod;
constexpr double Pi = 3.141592653589793;

template<class T> using prique = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second << "\n"; }
template<class InputIterator> void arrin(InputIterator first, InputIterator last) { for (; first != last; ++first) cin >> (*first); }
template<class InputIterator> void arrout(InputIterator first, InputIterator last) {
	for (; first != last; ++first) {
		cout << (*first) << ((first + 1) != last ? " " : "\n");
	}
}

constexpr bool pri(lint x) { for (lint i = 2; i * i <= x; ++i) if (x % i == 0) return false; return 1 < x; }

lint fact[3000000];
void fact_init(lint n, lint m = mod) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1] % m;
	}
}

lint modpow(lint x, lint n, lint m = mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r, lint m = mod) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], m - 2, m) % m * modpow(fact[r], m - 2, m) % m;
	return res < 0 ? res + m : res;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}


lint n, ans = 1000, kabu;
lint a[88];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n - 1) {
		if (a[i] < a[i + 1]) {
			kabu += ans / a[i];
			ans %= a[i];
			ans += kabu * a[i + 1];
			kabu = 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[110][100010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,W;
    cin >> N >> W;
    ll w[110], v[110];
    rep(i,0,N) cin >> w[i] >> v[i];
    dp[0][0] = 0;
    rep(i,0,N){
        rep(j,0,W+1){
            if(j - w[i] >= 0){
                dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]] + v[i]);
            }
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    print(dp[N][W]);


}

Measured memory_bytes: 79360
import Data.Bits
import qualified Data.ByteString.Char8 as C
import qualified Data.Vector.Unboxed as U

main = put =<< sol <$> (C.getLine *> get)

get = U.unfoldr (C.readInt . C.dropWhile (<'0')) <$> C.getLine

put = putStrLn . unwords . fmap show . U.toList

sol = U.map =<< xor . U.foldl1' xor

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    long long ww;
    cin>>ww;
    long long w[n+1];
    long long v[n+1];
    long long dp[n+1][ww+1];
    for(int i=1;i<=n;i++){cin>>w[i];
    cin>>v[i];
    }    long long t1,t2;
    long long t3;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){

            for(int j=1;j<=ww;j++){

                t1=dp[i-1][j];

                if(j>=w[i])t2=v[i]+dp[i-1][j-w[i]];
                else t2=0;
                dp[i][j]=max(t1,t2);
               // cout<<t1<<" "<<t2<<" |";
            }
            //cout<<"\n";
    }

    cout<<dp[n][ww];
    return 0;
}

Measured memory_bytes: 79232
n=int(input())
a=[0]*n
for _ in range(n):
	a[int(input())-1]=_

k=1
ans=1
for i in range(n-1):
	if a[i]<a[i+1]:
		k+=1
	else:
		ans=max(ans,k)
		k=1
print(n-max(ans,k))


Measured memory_bytes: 12228
#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007;
long long int dp[100000];
long long int dp_b[100000];
long long int White(vector <int> adj[],int node,int parent);

long long int Black(vector <int> adj[],int node,int parent)
{
	if(dp_b[node])
		return dp_b[node];

	if(adj[node].size()==1)
	{
		dp_b[node]=1ll;
		return dp_b[node];
	}
	dp_b[node]=1ll;
	for(auto x:adj[node])
		if(x!=parent)
		{
			dp_b[node] = (dp_b[node] * (White(adj,x,node) %M))%M;
		}
	return dp_b[node];
}

long long int White(vector <int> adj[],int node,int parent)
{
	if(dp[node])
		return dp[node];

	if(adj[node].size()==1)
	{
		dp[node]=1ll;
		return dp[node];
	}
	dp[node]=1ll;
	for(auto x:adj[node])
	{
		if(x!=parent)
		{
			dp[node] = (dp[node] * ((Black(adj,x,node)+White(adj,x,node))%M))%M;
		}
	}
	return dp[node];
}


int main()
{
    int n;
    cin>>n;
    vector <int> adj[n];
    for(int i=1;i<n;i++)
    {
    	int t1,t2;
    	cin>>t1>>t2;
    	t1--;
    	t2--;
    	adj[t1].push_back(t2);
    	adj[t2].push_back(t1);
    }

    if(n==1)
    	cout<<2<<endl;
    else if(n==2)
    	cout<<3<<endl;
    else
    {
    	if(adj[0].size()!=1)
    	{
	    	long long int ans=(White(adj,0,-1)+Black(adj,0,-1))%M;
	    	cout<<ans<<endl;
	    }
	    else
	    {
		    int root;
		    for(auto x:adj[0])
		    	if(adj[x].size()>1)
		    		root=x;
		    long long int ans=(White(adj,root,-1)+Black(adj,root,-1))%M;
		    	cout<<ans<<endl;
		}
	}
}


Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
int main(){
        string s;
        string t;
        bool a = true;
        cin >> s >> t;
        for(int i = 0; i < s.size(); i++){
                if(s[i] != t[i]){
                        a = false;
                        break;
                }
        }
        if(a)cout << "Yes" << endl;
        else cout << "No" << endl;
}


Measured memory_bytes: 3596
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;
#define mod int(1e9+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,a,b) for(int i=a;i<=b;i++)
#define repn(i,a,b) for(int i=b-1;i>=a;i--)
#define F first
#define S second
#define pb push_back
#define mk make_pair
typedef long long int ll;

int main()
{ ios_base::sync_with_stdio(false); cin.tie(0);
  ll n,a,b; cin>>n>>a>>b;
  string p; cin>>p;
  ll s=0,t=0;
  rep(i,n) {
    if(p[i]=='a') {
      if(s+t<a+b) { s++; cout<<"Yes"<<endl; }
      else cout<<"No"<<endl;
    }
    else if(p[i]=='b'){
      if(s+t<a+b && t<b) {t++; cout<<"Yes"<<endl;}
      else cout<<"No"<<endl;
      }
    else cout<<"No"<<endl;
 }
 return 0;
}


Measured memory_bytes: 848
import java.util.*;
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 i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        for (int i = 1; i < n; i++) {
            if (a[i - 1] == a[i]) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}

Measured memory_bytes: 65100
#include <stdio.h>
#define INF 20000000
#define NIL -1
#define WHITE 0
#define BLACK 1

int main(){
  int i,j,mincost,u,v,sum=0;
  int n,a[101][101],d[101],pi[101],color[101];

  //input
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      scanf("%d",&a[i][j]);
      if(a[i][j]==-1)a[i][j]=INF;
    }
  }
  //processing
  for(i=1;i<=n;i++){
    d[i] = INF;
    pi[i] = NIL;
    color[i] = WHITE;
  }
  d[1] = 0;
  while(1){
    mincost=INF;
    for(i=1;i<=n;i++){
      if(color[i]!=BLACK&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==INF)break;
    color[u]=BLACK;
    for(v=1;v<=n;v++){
      if(color[v]!=BLACK&&a[u][v]<d[v]&&a[u][v]!=-1){
	pi[v]=u;
	d[v]=a[u][v];
      }
    }
  }
  for(i=1;i<=n;i++){
    sum+=d[i];
  }
  //output
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 636
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll N;
    cin >> N;
    string s, t;
    cin >> s;
    cin >> t;
    rep(i,0,N) {
        cout << s[i] << t[i];
        if (i == N-1) {
            cout << endl;
        }
    }
}



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

using namespace std;

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

  int l = 0, r = s.size() - 1;
  int ans = 0;
  while (l < r) {
    if (s[l] == 'x' && s[r] == 'x') {
      l++; r--;
    } else if (s[l] == 'x') {
      l++; ans++;
    } else if (s[r] == 'x') {
      r--; ans++;
    } else if (s[l] == s[r]) {
      l++; r--;
    } else {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
using namespace std;

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



Measured memory_bytes: 256
#include<iostream>

using namespace::std;
#define int long long int
#define MOD 1000000007

int fact[2000005];

int pw(int b,int e){
	if(!e) return 1;
	int t=pw(b,e/2);
	t=(t*t)%MOD;
	if(e&1) t=(t*b)%MOD;
	return t;
}

int32_t main(){
	int k;
	cin>>k;
	string s;
	cin>>s;
	int n=s.length();
	int ans=pw(26,n+k);
	// cout<<ans<<'\n';
	fact[0]=1;
	for(int i=1;i<=2000000;i++)
		fact[i]=(fact[i-1]*i)%MOD;
	for(int i=0;i<n;i++)
		ans=(ans-((((((fact[n+k]*pw(fact[i],MOD-2))%MOD)*pw(fact[n+k-i],MOD-2))%MOD)*pw(25,n+k-i))%MOD)+MOD)%MOD;//,cout<<i<<' '<<((((((fact[n+k]*pw(fact[i],MOD-2))%MOD)*pw(fact[n+k-i],MOD-2))%MOD)*pw(25,n+k-i))%MOD)<<'\n';
	cout<<ans<<'\n';
}

Measured memory_bytes: 20016
n = int(input())
s = input()

ans = []

t = n%26

li1 = {0:"A", 1:"B", 2:"C", 3:"D", 4:"E", 5:"F", 6:"G", 7:"H", 8:"I", 9:"J", 10:"K", 11:"L", 12:"M", 13:"N", 14:"O", 15:"P", 16:"Q", 17:"R", 18:"S", 19:"T", 20:"U", 21:"V", 22:"W", 23:"X", 24:"Y", 25:"Z"}
li2 = {"A":0, "B":1, "C":2, "D":3, "E":4, "F":5, "G":6, "H":7, "I":8, "J":9, "K":10, "L":11, "M":12, "N":13, "O":14, "P":15, "Q":16, "R":17, "S":18, "T":19, "U":20, "V":21, "W":22, "X":23, "Y":24, "Z":25}

for i in range(len(s)):
    temp = li2[s[i]]
    temp += t
    if temp > 25:
        temp -= 26
    
    ans.append(li1[temp])

print("".join(ans))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000001
#define MOD 1e9+7

int main(){
	int n;
	cin>>n;
	int c[n],v[n];
	for(int i=0;i<n;i++)cin>>v[i];
	for(int i=0;i<n;i++)cin>>c[i];
	int ans=0;
	int va=0,co=0;
	for(int i=0;i<pow(2,n);i++){
		va =0;co=0;
		for(int j=0;j<n;j++){
			if((1&i>>j)==1){
				va+=v[j];
				co+=c[j];
			}
		}
		ans=max(ans,va-co);
	}
	cout<<ans<<endl;
}


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

using namespace std;

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)

int main(int argc, char const *argv[]){
	int num, input, count;
	long long int ans, min;
	while(cin >> num){
		ans = 0;
		min = 1000000000;
		for (int i = 0; i < num; ++i){
			cin >> input;
			ans += abs(input);
			min = min < abs(input)? min :abs(input);
			if (input < 0)
				count += 1;
		}

		if (count%2){
			ans -= 2*min;
		}

		cout << ans << endl;
	}

	return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD =  1000000007;
const ll INF = 1LL << 60;


int main() {
    int n, k; cin >> n >> k;
    V<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = k; i < n; i++){
        if(a[i - k] < a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 4796
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(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 (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
// const ll mod = 1000000007;
const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

bool solve(){
  ll s,w;cin>>s>>w;

  bool ans=(s<=w);
  cout<<(ans ? "unsafe" : "safe")<<endl;
  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V){os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P){return os << "(" << P.first << "," << P.second << ")";}
#ifndef ONLINE_JUDGE
#define TRACE
#endif

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...) 1
#endif
#define mp make_pair
#define pb push_back
#define endl '\n'
#define F first
#define S second
#define I insert 
typedef long double ld;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
const int N = 1e5+5;
ll h[N], dp[N];
const ll INF = 1e12;

ll go(ll a){
	ll &ans = dp[a];
	if(ans != -1) return ans;

	ans = INF;
	if(a == 1) {ans = 0; goto aa;}
	ans = min(ans, go(a-1)+abs(h[a]-h[a-1]));
	if(a-2 >= 1) ans = min(ans, go(a-2)+abs(h[a]-h[a-2]));
	aa:
	return ans;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<setprecision(25);
    ll n; cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>h[i];
    }
    fill(dp,dp+1+n,-1);
    cout<<go(n)<<endl;
}

Measured memory_bytes: 4992
import fractions # python 3.4.3
# import copy
from functools import reduce

N=int(input())

A=list(map(int,input().split()))
# A.sort()

# n個目までの最小公約数
dp=[0 for _ in range(N+1)]
dpRev=[0 for _ in range(N+1)]

def gcd(a,b):
	if a == 0: 
		return b
	elif b == 0: 
		return a
	# print(a,b)
	return reduce(fractions.gcd, (a,b))

dp[0]=0
for n in range(0,N):
	dp[n+1]=gcd(dp[n],A[n])

dpRev[N]=0
for n in range(N-1,-1,-1):
	dpRev[n]=gcd(A[n],dpRev[n+1])

# print(dp)
# print(dpRev)


ans=0
for n in range(N):
	ans = max( ans, gcd(dp[n],dpRev[n+1]) )


print(ans)


Measured memory_bytes: 16144
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
// #ifndef ONLINE_JUDGE
//        // for getting input from input.txt
//        freopen("input.txt", "r", stdin);
//        // for writing output to output.txt
//        freopen("output.txt", "w", stdout);
// #endif
	int n,d,x,t=0;
	cin>>n>>d>>x;
	vector<int> v(n,0);
	for (int i = 0; i < n; ++i)
	{
		cin>>v[i];
	}
	for (int i = 0; i < n; ++i)
	{
		/* code */
		t = t + (1+ (d-1)/v[i]);
	}
	cout<<t+x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  ll a;
  cin >> a;
  double b_;
  cin >> b_;
  
  ll b=(ll)(100*b_+.5);
  //cout << b << " " << (ll)(b_*100) << endl;

  cout << (a*b)/100 << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int minus = 0;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    if(A.at(i) < 0) {
      minus++;
    }
  }
  if(minus % 2 == 0) {
    int64_t ans = 0;
    for(int i = 0; i < N; i++) {
      ans += abs(A.at(i));
    }
    cout << ans << endl;
  }
  else {
    // 絶対値が一番小さいものをaとする
    int64_t a = 1000000000;
    int64_t ans = 0;
    for(int i = 0; i < N; i++) {
      if(abs(A.at(i)) < a) {
        a = abs(A.at(i));
      }
      ans += abs(A.at(i));
    }
    ans -= 2 * a;
    cout << ans << endl;
  }
}

Measured memory_bytes: 4012
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define int long long
#define ll long long
#define mod (int)1000000007
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = DBL_EPSILON;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
int n, p, a[200010], b[10010];
string s;
signed main() {
	cin >> n >> p >> s;
	if (p == 5) {
		int ans = 0;
		rep(i, n) {
			if (s[i] == '0' || s[i] == '5') {
				ans += i + 1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	if (p == 2) {
		int ans = 0;
		rep(i, n) {
			if (s[i] == '0' || s[i] == '2' || s[i] == '4' || s[i] == '6' || s[i] == '8') {
				ans += i + 1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	reverse(all(s));
	rep(i, n) {
		a[i] = (s[i] - '0') * modpow(10, i, p) % p;
		if (i)a[i] += a[i - 1];
		a[i] %= p;
		b[a[i]]++;
	}
	int ans = 0;
	rep(i, n) {
		if (i)ans += b[a[i - 1]];
		else ans += b[0];
		b[a[i]]--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 300000, mod = 998244353;
ll k;
int n, a, b, ans;
int add(int x, int y) {
	x += y; return x < mod ? x : x - mod;
}
int dec(int x, int y) {
	x -= y; return x < 0 ? x + mod : x;
}
int mul(int x, int y) {
	return 1ll * x * y % mod;
}
int fac[maxn + 10], inv[maxn + 10], ifac[maxn + 10];

void pre() {
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= maxn; ++i) {
		fac[i] = mul(fac[i - 1], i);
		inv[i] = i == 1 ? 1 : dec(0, mul(mod / i, inv[mod % i]));
		ifac[i] = mul(ifac[i - 1], inv[i]);
	}
}

int comb(int x, int y) {
	return mul(fac[x], mul(ifac[y], ifac[x - y]));
}

int main() {
	pre();
	scanf("%d%d%d%lld", &n, &a, &b, &k);
	for (int i = 0; i <= n; ++i) {
		ll t = k - 1ll * a * i;
		if (t % b || t / b < 0 || t / b > n) continue;
		ans = add(ans, mul(comb(n, i), comb(n, t / b)));
	}
	printf("%d", ans);
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){

	COMinit();

	lli n,k;
	cin>>n>>k;
	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];
	sort(a.begin(),a.end());

	lli ans = 0;

	//max
	for(lli i=0;i<n;i++){
		ans += (a[n-1-i]*COM(n-1-i,k-1))%MOD;
		while(ans<0)ans +=MOD;
		ans %= MOD;
	}

	//min
	REP(i,0,n){
		ans -= ((a[i])*COM(n-1-i,k-1))%MOD;
		while(ans<0)ans +=MOD;
		ans %= MOD;
	}
	cout<<ans%MOD<<endl;


	return 0;
}

Measured memory_bytes: 12928
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/
#include<iostream>
using namespace std;

int main() {
	int w, h, x, y, r, a, b, c, d;
	cin >> w >> h >> x >> y >> r;

	/*右下を定義*/
	a = x - r;
	if (a < 0) {
		cout << "No" << endl;
		return 0;
	}
	b = y - r;
	if (b < 0) {
		cout << "No" << endl;
		return 0;
	}
	
	/*左上を定義*/
	c = x + r;
	if (c > w) {
		cout << "No" << endl;
		return 0;
	}
	
	d = y + r;
	if (d > h) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll a,b;
    cin>>a>>b;
    cout<<max((a+b),max((a-b),(a*b)))<<endl;
    return 0;
}


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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

bool seen[200005];
ll cum[200005];
void dfs(vii &graph, int idx, int par) {
    seen[idx] = true;
    foreach (e, graph[idx]) {
        if (seen[e]) continue;
        cum[e] += cum[idx];
        dfs(graph, e, idx);
    }
}

// sort the graph topologically for DAG (Directed Acyclic Graph)
// https://www.hamayanhamayan.com/entry/2019/01/08/234649
// 使用例:https://atcoder.jp/contests/dp/submissions/10559518
struct TopologicalSort {
    vector<vector<int>> edge;
    vector<int> sorted;
    TopologicalSort(int n) : edge(n), sorted(n) {}

    void add_edge(int a, int b) {
        edge[a].push_back(b);
    }

    bool visit(int v, vector<int> &order, vector<int> &color) {
        color[v] = 1;
        for (int u : edge[v]) {
            if (color[u] == 2) continue;
            if (color[u] == 1) return false;
            if (!visit(u, order, color)) return false;
        }
        order.push_back(v);
        color[v] = 2;
        return true;
    }

    // false: cannot sort (not DAG)
    bool sort() {
        int n = edge.size();
        vector<int> color(n);
        for (int u = 0; u < n; u++)
            if (!color[u] && !visit(u, sorted, color)) return false;
        reverse(sorted.begin(), sorted.end());
        return true;
    }
};

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

    int n, q;
    cin >> n >> q;
    TopologicalSort ts(n);

    rep(i, n - 1) {
        int from, to;
        cin >> from >> to;
        from--, to--;
        ts.add_edge(from, to);
        ts.add_edge(to, from);
    }

    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        cum[p] += x;
    }

    dfs(ts.edge, 0, -1);
    rep(i, n)
        out(cum[i]);
}


Measured memory_bytes: 25216
<?php
# 入力部
// fscanf(STDIN, "%s %s", $s, $t);
fscanf(STDIN, "%d %d", $a, $b);
// fscanf(STDIN, "%s", $u);
// fscanf(STDIN, "%d %d", $k, $x);
// $s1 = fgets(STDIN); //"\n"の2文字
// $s2 = fgets(STDIN);
// fscanf(STDIN, "%d", $r);
// fscanf(STDIN, "%d", $b);
// fscanf(STDIN, "%s", $s);
// fscanf(STDIN, "%c", $c);
// fscanf(STDIN, "%s", $s2);
// fscanf(STDIN, "%d %d %d", $a, $b, $c);


# 処理部
// $arr = str_split($s);
// $arr2 = str_split($s2);
// $arr1 = explode(" ", $s1);
// $arr2 = explode(" ", $s2);
// for ($i = 0; $n > $x * $i; $i++) {
// }
// if (strpos($s, 'RRR') !== false) {
//   $r = 3;
// } elseif (strpos($s, 'RR') !== false) {
//   $r = 2;
// } elseif (strpos($s, 'R') !== false) {
//   $r = 1;
// } else {
//   $r = 0;
// }
// $s = "No";
// if ($x >= 30) {
//   $s = "Yes";
// }
// for ($i = 0; $i * 1000 < $n; $i++) {
// }
// $c = "a";
// if (ctype_upper($a)) {
//   $c = "A";
// }
// $s = "Yes";
// echo count($arr1);
// for ($i = 0; $i < strlen($s1); $i++) {
//   if ($arr1[$i] != $arr2[$i]) {
//     $s = "No";
//   }
// }
// $unit;
// switch ($n % 10) {
//   case 0:
//   case 1:
//   case 6:
//   case 8:
//     $unit = "pon";
//     break;
//   case 3:
//     $unit = "bon";
//     break;
//   default:
//     $unit = "hon";
//     break;
// }
// if ($s == "ABC") {
//   $r = "ARC";
// } else {
//   $r = "ABC";
// }
// $r = "NG";
// $arr = array("SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN");
// for ($i = 0; $i <= count($arr); $i++) {
//   if ($arr[$i] == $s) {
//     break;
//   }
// }
// $r = "safe";
// if ($s <= $w) {
//   $r = "unsafe";
// }
// $r = "No";
// if (strpos($n, "7") !== false) {
//   $r = "Yes";
// }
// $r = "No";
// if ($arr[2] == $arr[3] && $arr[4] == $arr[5]) {
//   $r = "Yes";
// }
// $r = "Yes";
// if ($s == "AAA" || $s == "BBB") {
//   $r = "No";
// }
// if ($n % 2 == 0) {
//   $r = $n / 2;
// } else {
//   $r = ($n + 1) / 2;
// }
// if ($n < 10) {
//   $r += (10 - $n) * 100;
// }
// $arr = array($a, $b, $c);
// $arr = array_unique($arr);
// if (count($arr) == 2) {
//   $r = "Yes";
// } else {
//   $r = "No";
// }
// if ($s == $u) {
//   $a--;
// } else {
//   $b--;
// }
// for ($i = 0; $h > 0; $i++) {
//   $h -= $a;
// }
// $r = "No";
// if ($n == $m) {
//   $r = "Yes";
// }
// $r = "win";
// if ($a + $b + $c >= 22) {
//   $r = "bust
// ";
// }
// $arr = array(1, 2, 3);
// unset($arr[$a - 1]);
// unset($arr[$b - 1]);
// $arr = array_values($arr);
// if ($n < 10 && $m < 10) {
//   $r = $n * $m;
// } else {
//   $r = -1;
// }
if ($a > $b * 2) {
  $r = $a - $b * 2;
} else {
  $r = 0;
}

# 出力部
// echo ($n * ($n - 1) / 2) + ($m * ($m - 1) / 2) . "\n";
// echo $z . " " . $x . " " . $y . "\n";
// echo ($i * 1000) - $n . "\n";
// echo json_encode($arr) . "\n";
// echo $arr[0] . "\n";
// echo $i + 1 . "\n";
echo $r . "\n";
// echo ++$c . "\n";
// echo $a . " " . $b . "\n";
// echo $t . $s . "\n";


Measured memory_bytes: 16228
import math

a, b, C = map(float,input().split())
radian_C = math.radians(C)
sinC = math.sin(radian_C)
cosC = math.cos(radian_C)

#aを底辺とした時の高さh
h = b * sinC

#三角形の面積S
S = a * h * 0.5

#週の長さ
c = (a**2+b**2-(2*a*b*cosC))**0.5
L = a + b + c

print(S)
print(L)
print(h)



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

int main() {
    int N, L;
    cin >> N >> L;
    string S[N];
    for (int i = 0; i < N; ++i) cin >> S[i];

    sort(S, S + N);  // a[0:N] を大きい順にソート
    for (int i = 0; i < N; ++i){
        cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#define F first
#define S second
using namespace std;
int n,m;
int c;
int f[22][22];
typedef pair<int,int> P;
vector<P> v;

int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
bool used[33];
map<P,int> dp;
int solve(int bit,int h){
  //cout << h << " = (" << v[h].F << "," << v[h].S << ")" << endl;
  if(bit == (1<<c)-1){
    if(v[h].F == v[0].F || v[h].S == v[0].S){
      return 1;
    }
    return 0;
  }

  if(dp.find(P(bit,h)) != dp.end()){
    //cout << h << " = (" << v[h].F << "," << v[h].S << ") : " << dp[P(bit,h)] << endl;
    return dp[P(bit,h)];
  }

  int ret = 0;
  for(int i = 0; i < 4; i++){
    int nx = v[h].F + dx[i];
    int ny = v[h].S + dy[i];
    while(0 < nx && nx <= n && 0 < ny && ny <= m){
      if(f[nx][ny] && !used[f[nx][ny]]){
	used[f[nx][ny]] = true;
	ret += solve(bit | (1<<f[nx][ny]),f[nx][ny]);
	used[f[nx][ny]] = false;
	break;
      }
      nx += dx[i];
      ny += dy[i];
    }
  }
  //cout << h << " : " << ret << endl;
  if(__builtin_popcount(bit) > 18) dp[P(bit,h)] = ret;
  return ret;
}

int main(void){
  while(1){
    cin >> n >> m; if(!n) break;
    c = 1;
    v.clear();
    v.push_back(P(0,0));
    memset(f,0,sizeof(f));
    memset(used,false,sizeof(used));
    for(int i = 1; i <= m; i++){
      for(int j = 1; j <= n; j++){
	cin >> f[j][i];
	if(f[j][i] == 2){
	  v[0].F = j;
	  v[0].S = i;
	  f[j][i] = 0;
	}else if(f[j][i] == 1){
	  f[j][i] = c;
	  v.push_back(P(j,i));
	  c++;
	}
      }
    }

    dp.clear();
    cout << solve(1,0) << endl;
    //break;
  }
}

Measured memory_bytes: 14704
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import copy

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''

tes = stdin.readline().rstrip().split()
a = int(tes[0])
b = int(tes[1])
res = a - b * 2
if (res <= 0):
    print(0)
else:
    print(res)


Measured memory_bytes: 3564
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


int main(){
  int N;
  cin >> N;
  cout << (N+1)/2 << endl;
  
}


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

using namespace std;

int h, w;
vector<string> painting;
int deltas[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

bool check(int i, int j) {
  for (auto d : deltas) {
    int ii = i + d[0];
    int jj = j + d[1];

    if (ii < 0 || jj < 0 || ii >= h || jj >= w) continue;
    if (painting[ii][jj] == '#') return true;
  }
  return false;
}

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

  cin >> h >> w;
  painting.resize(h);
  for (int i = 0; i < h; i++) cin >> painting[i];

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (painting[i][j] == '#') {
        if (!check(i, j)) {
          cout << "No" << endl;
          return 0;
        }
      } 
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
n,a,b = map(int, input().split())

m = n//(a+b)
s = n%(a+b)
if n < a+b:
    if n <= a:
        print(n)
    else:
        print(a)
else:
    if s <= a:
        print(a*m+s)
    else:
        print(a*m+a)


Measured memory_bytes: 2940
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let d:usize = read();
    let mut matrix = vec![vec![0.0f64; d]; n];
    for i in 0..n {
        for j in 0..d {
            matrix[i][j] = read();
        }
    }
    let mut ans = 0;
    for i in 0..n {
        for j in i+1..n {
            let mut coordinate = 0.0;
            for k in 0..d {
                coordinate += (matrix[i][k] - matrix[j][k]).powf(2.0);
            }
            coordinate = coordinate.sqrt();
            if coordinate == coordinate.floor() {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		 try{

			 int S = Integer.parseInt(br.readLine());

			 System.out.printf("%d:%d:%d\n",S/3600,(S%3600)/60,S%60);

		 }catch(IOException e){
			 e.printStackTrace();
		 }
	}
}




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

int main() {
 int N;
 cin >> N;
 int i;
 int num = 0;
 int l, r, s;
 for (i = 0; i < N; i++){
	 cin >> l >> r;
	 s = r - l + 1;
	 num += s;
 }
 cout << num << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

struct Mod {
    static uint64_t PRIME;
    struct LocalPrime {
        uint64_t backup;
        LocalPrime(uint64_t prime) { backup = exchange(Mod::PRIME, prime); }
        ~LocalPrime() { Mod::PRIME = backup; }
    };
    uint64_t value = 0;
    Mod()
    : value(0) {}
    Mod(ll v) {
        if (v >= 0) {
            value = v % PRIME;
        } else {
            value = PRIME - (-v) % PRIME;
        }
    }
    Mod operator+(const Mod& rhs) const { return Mod(*this) += rhs; }
    Mod& operator+=(const Mod& rhs) {
        value += rhs.value;
        if (value >= PRIME) {
            value -= PRIME;
        }
        return *this;
    }
    Mod operator-(const Mod& rhs) const { return Mod(*this) -= rhs; }
    Mod& operator-=(const Mod& rhs) {
        if (value < rhs.value) {
            value += PRIME;
        }
        value -= rhs.value;
        return *this;
    }
    Mod operator*(const Mod& rhs) const { return Mod(*this) *= rhs; }
    Mod& operator*=(const Mod& rhs) {
        value = (value * rhs.value) % PRIME;
        return *this;
    }
    Mod inv() const { return power(*this, PRIME - 2); }
    Mod operator/(const Mod& rhs) const { return Mod(*this) /= rhs; }
    Mod& operator/=(const Mod& rhs) {
        *this *= rhs.inv();
        return *this;
    }
    static Mod power(Mod rhs, ll exp) {
        Mod ans = 1;
        while (exp > 0) {
            if (exp % 2) {
                ans *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return ans;
    }
};
uint64_t Mod::PRIME = 1000000007;

vector<ll> euler_phi_upto(ll N) {
    vector<ll> phi(N+1);
    rep(n,1,N+1) {
        phi[n] = n;
    }
    rep(n,2,N+1) {
        if (phi[n] == n) {
            for (ll m = n; m <= N; m += n) {
                phi[m] = (phi[m] / n) * (n - 1);
            }
        }
    }
    return phi;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> phi = euler_phi_upto(K);
    Mod ans = 0;
    rep(x,1,K+1) {
        ans += Mod(phi[x]) * Mod::power(Mod(K / x), N);
    }
    cout << ans.value << endl;
}


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

int main() {
    int N, D; cin >> N >> D;
    int X[20][20];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int c = 0;
    double dist = 0.;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            dist = 0;
            for (int d = 0; d < D; d++) {
                dist += pow((X[i][d] - X[j][d]), 2);
            }
            dist = sqrt(dist);
            if (dist == floor(dist)) c++;
        }
    }

    cout << c << endl;
    return 0;
}

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

int main(){
    int y,m,d;
    char c1,c2;
    cin>>y>>c1>>m>>c2>>d;
    if(m<=4)cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;

    return 0;
}

Measured memory_bytes: 3592
def examD():
    N = I()
    a = LI();  b = LI()
    cura = [0]*N; curb=[0]*N
    ans = 0
    for i in range(28,-1,-1):
        T = (2 ** i)
        for j in range(N):
            cura[j] = a[j]%(2**(i+1))
            curb[j] = b[j]%(2**(i+1))
        curb.sort()
        cura.sort(reverse=1)
        f, l1, r1, l2 = 0, 0, 0, 0
        for x in cura:
            while l1 < N and x + curb[l1] < T:
                l1 += 1
            while r1 < N and x + curb[r1] < 2 * T:
                r1 += 1
            while l2 < N and x + curb[l2] < 3 * T:
                l2 += 1
            f += N - l2 + r1 - l1
        ans += T * (f & 1)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


Measured memory_bytes: 119928
#include <stdio.h>

#define MOD 1000000007
int n;
char s[110000];
int table[30];
int main(){
	unsigned long long ans = 1;
	scanf("%d%s", &n, s);
	for(int i = 0; i < n; ++i) ++table[s[i] - 'a'];
	for(int i = 0; i < 26; ++i) ans = ans * (table[i] + 1) % MOD;
	printf("%llu\n", ans - 1);
}


Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize,
        a: [u64; n],
    }
    let mut r = 1000;
    let mut s = 0;

    for i in 0..n - 1{
        r += s * a[i];
        s = 0;
        if a[i] < a[i + 1] {
            s = r / a[i];
            r -= s * a[i];
        }
    }
    r += s * a[n - 1];
    println!("{}", r);
}


Measured memory_bytes: 2132
n = int(raw_input())
c = []
s = []
f = []
f_of = []

for a in range(n-1):
  x,y,z = map(int,raw_input().split(" "))
  c.append(x)
  s.append(y)
  f.append(z)
  f_of.append(y/z) # when this train start?

for a in range(n):
  now = 0
  for b in range(a,n-1):
    if now % f[b] != 0:
      buf = f[b] - (now % f[b])
    else:
      buf = 0
    if (now+buf) < f[b]*f_of[b]:
      now = f[b]*f_of[b] + c[b]
    else:
      now = now + buf + c[b]
  print now


Measured memory_bytes: 2692
#include<iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    long long h[110000];
    long long dp[110000];
    
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = 1000000007;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};

ll pw(ll a){
	return a*a*a*a*a;
}

void solve(){
	
	ll x;
	cin >> x;
	for(ll i = 0; i <= 1000; i++){
		for(ll j = 0; j<=1000;j++){
			if(pw(i)-pw(j) == x){
				cout << i << ' ' << j;
				return;
			} 
			if(pw(-i)-pw(j) == x){
				cout << -i << ' ' << j;
				return;
			}
			if(pw(i)-pw(-j) == x){
				cout << i << ' ' << -j;
				return;
			}
			if(pw(-i)-pw(-j) == x){
				cout << -i << ' ' << -j;
				return;
			}
		}
	}
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


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

int main() {
  int a,a1,a2,a3;
  cin >> a;
  a1 = a/100;
  a2 = a/10 -a1*10;
  a3 = a - a1*100 - a2*10;
  cout << a1 + a2+ a3<< endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
A = []
ans = 0
for j in range(k):
    A.append([])
for i in range(n):
    A[i%k].append(t[i])
for l in range(k):
    for t in range(1,len(A[l])):
        if A[l][t] == A[l][t-1]:
            A[l][t] = 0
    for t in range(len(A[l])):
        if A[l][t] == "r":
            ans += p
        elif A[l][t] == "s":
            ans += r
        elif A[l][t] == "p":
            ans += s
print(ans)

Measured memory_bytes: 13436
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> P;
#define fr first
#define sc second
P seg[1<<18];
int n;
void update(int id,int pt){
  int k = id + n - 1;
  seg[k].fr += pt;
  seg[k].sc = -id;
  while(k != 0){
    k = ( k - 1 ) / 2;
    seg[k] = max(seg[2*k+1],seg[2*k+2]);
  }
}
void init(int size) {
  n = 1;
  while(n < size) n *= 2;
}
int main(){
  int N,R,L;
  cin >> N >> R >> L;
  init(N);
  for(int i = 0 ; i < N ; i++ ) update(i,0);
  int mostid = 0 , now = 0 , sum[100000] = {};
  for(int i = 0 ; i < R ; i++ ){
    int d,t,x;
    cin >> d >> t >> x;
    update(d-1,x);
    sum[mostid] += t - now;
    now = t;
    mostid = -seg[0].sc;
  }
  sum[mostid] += L - now;
  int rec = 0;
  for(int i = 0 ; i < N ; i++) if( sum[rec] < sum[i] ) rec = i;
  cout << rec + 1 << endl;
}

Measured memory_bytes: 3608