akhauriyash/Code-Regression huggingface dataset:
# frozen_string_literal: true

def solve(n, xs)
  cnt = ps = r = 0
  for l in 0...n
    while r < n
      break if (ps + xs[r]) != (ps ^ xs[r])
      ps ^= xs[r]
      r += 1
    end
    cnt += (r - l)
    ps ^= xs[l]
  end
  cnt
end

def read
  [gets.to_i, gets.split.map(&:to_i)]
end

def test
  puts [
    solve(4, [2, 5, 4, 6]) === 5,
    solve(9, [0, 0, 0, 0, 0, 0, 0, 0, 0]) === 45,
    solve(
      19, [885, 8, 1, 128, 83, 32,
           256, 206, 639, 16, 4, 128,
           689, 32, 8, 64, 885, 969, 1]
    ) === 37
  ].all?
end

# test
puts solve(*read)


Measured memory_bytes: 15372
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;

const double EPS = 1e-8, INF = 1e12, PI = acos(-1.0);
typedef complex<double> P;
namespace std{
	bool operator<(const P& a, const P& b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
inline double cross(const P& a, const P& b){ return imag(conj(a)*b); }
inline double dot(const P& a, const P& b){ return real(conj(a)*b); }
struct L : public vector<P>{
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};
typedef vector<P> G;

inline int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if(cross(b, c) > 0)   return +1;		// counter clockwise
	if(cross(b, c) < 0)   return -1;		// clockwise
	if(dot(b, c) < 0)     return +2;		// c--a--b on line
	if(norm(b) < norm(c)) return -2;		// a--b--c on line
	return 0;
}
double dist(double x, double y, double z){
	return sqrt(x*x + y*y+ z*z);
}
int n, l[10];
P p[10];

int main(){
	while(cin >> n, n){
		rep(i, n) cin >> p[i].real() >> p[i].imag() >> l[i];
		
		double ans = 0;
		rep(i, n){
			bool ok = 1;
			rep(j, n){
				if(dist(p[i].real() - p[j].real(), p[i].imag() - p[j].imag(), l[i]) > l[j] + EPS) ok = 0;
			}
			if(ok) ans = max(ans, (double)l[i]);
		}
		
		rep(a, n) rep(b, n) rep(c, n) if(a != b){
			double t = arg(p[b] - p[a]);
			double x = (l[a] * l[a] - l[b] * l[b] + norm(p[b] - p[a])) / (2 * abs(p[b] - p[a]));
			double r = sqrt(l[a] * l[a] - x * x);
			P o = p[a] + (p[b] - p[a]) / abs(p[b] - p[a]) * x;
			o *= P(cos(-t), sin(-t));
			P q = p[c] * P(cos(-t), sin(-t));
			
			double lo = 0, hi = PI / 2, mid;
			rep(it, 100){
				mid = (lo + hi) / 2;
				double ty = o.imag() + r * cos(mid), tz = r * sin(mid);
				if(dist(q.real() - o.real(), q.imag() - ty, tz) > l[c]) hi = mid;
				else lo = mid;
			}
			double th = r * sin(mid);
			P tmp(o.real(), o.imag() + r * cos(mid));
			tmp *= P(cos(t), sin(t));
			bool ok = 1;
			rep(i, n){
				if(dist(tmp.real() - p[i].real(), tmp.imag() - p[i].imag(), th) > l[i] + EPS) ok = 0;
			}
			if(ok) ans = max(ans, th);
			
			ok = 1;
			tmp = p[a] + (p[b] - p[a]) / abs(p[b] - p[a]) * x;
			rep(i, n){
				if(dist(tmp.real() - p[i].real(), tmp.imag() - p[i].imag(), r) > l[i] + EPS) ok = 0;
			}
			if(ok) ans = max(ans, r);
			
		}
		printf("%.9f\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1392
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;

int n,p[100000];


string ans;

signed main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>p[i];

  stack<int> st;
  int x=1;
  string ans;
  for(int i=0;i<n;i++){
    while(x<=p[i])st.push(x++),ans+='(';
    int y=st.top();
    if(y!=p[i]){cout<<":("<<endl;return 0;}
    ans+=')';
    st.pop();
  }
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 4376
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main(){

    queue<int> que;
    queue<string> pnum;
    int n, q;
    int num;
    string p;

    cin >> n >> q;

    for(int i=0; i<n; i++){
        cin >> p >> num;
        pnum.push(p);
        que.push(num);
    }

    int sum=0;
    int current;
    string cs;
    while(pnum.size() != 0){

       cs = pnum.front();       pnum.pop();
       current = que.front();   que.pop();

       if(current - q <= 0){
           sum += current;
           cout << cs << " " << sum << endl;
       }else{
           sum += q;
           current -= q;
           que.push(current);
           pnum.push(cs);
       }
    }

    return 0;
}

Measured memory_bytes: 5672
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()



int main() {
    int N,Y;
    cin>>N>>Y;
    int res10000=-1,res5000=-1,res1000=-1;
    for(int a=0;a<=N;a++){
        for(int b=0;b+a<=N;b++){
            int c=N-a-b;
            int total=10000*a+5000*b+1000*c;
            if(total==Y){
                res10000=a;
                res5000=b;
                res1000=c;
            }
        }
    }
    cout<<res10000<<" "<<res5000<<" "<<res1000<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

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


}

Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;
use std::cmp::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed 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 k: usize = read();
    let mut ans = 0;
    for b in 1..n+1 {
        if b <= k { continue; }
        let cnt = n / b;
        ans += cnt * (b - k);
        let rest = n - cnt * b;
        if rest >= k {
            ans += rest - (max(1, k) - 1);
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring> 
#include <algorithm>
#include <stack> 
#define ll long long
int n,k,h,w;
int main()
{
	cin>>n>>h>>w;
	cout<<(n-h+1)*(n-w+1);
	return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<chrono>
#include<random>
#include<cstdio>
#include<set>
#include<map>
#include<numeric>
#include<cfenv>
#include<cmath>
#define MAX_N pow(10,6)
#define MAX_M pow(10,6)
#define INF pow(10,6)
#define REP(i,n) for(long long i=0;i<n;i++)
typedef long long ll;
using namespace std;

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

int main(){
    ll A,B;
    cin>>A>>B;
    cout<<A*B/gcd(A,B);
}

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

int main(){

   int n,x;
   cin>>n>>x;

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

   int cnt=1;

   int d=0;

   for(int i=0;i<n;i++){
       d+=l[i];
       if(d<=x)cnt+=1;
   }

cout<<cnt<<endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main() {
  ll x;
  cin >> x;
  ll value = 100;
  int count = 0;
  while (true) {
    count++;
    value = value + value * 0.01;
    // cout << "i = " << count << ", value = " << value << endl;
    if (value >= x) {
      cout << count << endl;
      break;
    }
  }
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, l, t;
	cin >> n >> l >> t;
	vi x(n), w(n);
	rep(i,0,n) cin >> x[i] >> w[i];

	ll cnt = 0;

	rep(i,1,n) if(w[i] != w[0]){
		int dist = x[i]-x[0];
		if(w[0]==2) dist = l-dist;
		ll tt = 2*t;
		cnt += tt/l;
		tt %= l;
		if(tt > dist)
			++cnt;
	}
	cnt %= n;
	if(w[0]==2) cnt = (n-cnt)%n;
	vector<pii> ans(n);
	rep(i,0,n) ans[i] = {((x[i]+(w[i]==1 ? 1 : -1)*t)%l+l)%l, (w[0]==1 ? 1 : -1)*i};
	sort(all(ans));
	int zpos;
	rep(i,0,n) if(ans[i].second == 0) zpos = i;
	int beg = (n+zpos-cnt)%n;
	rep(i,0,n) cout << ans[(beg+i)%n].first << endl;
}

Measured memory_bytes: 2816
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n,k = lr()
s = sr()
length1 = 0
tmp1 = 0
one = []
for c in s:
    if c == '1':
        tmp1+=1
    else:
        if tmp1 != 0:
            length1 += 1
            one.append(tmp1)
            tmp1 = 0
if tmp1 != 0:
    length1 += 1
    one.append(tmp1)

if length1 == 0:
    print(len(s))
    sys.exit()

zero = [0 for i in range(length1+1)]
ind = 0
while ind != n and s[ind] == '0':
    zero[0]+=1
    ind+=1
tmp0 = 0
ind0 = 1
while ind != n:
    while ind != n and s[ind] == '1':
        if tmp0 != 0:
            zero[ind0] = tmp0
            tmp0 = 0
            ind0+=1
        ind+=1
    while ind != n and s[ind] == '0':
        tmp0+=1
        ind+=1
if tmp0 != 0:
    zero[-1] = tmp0

a2 = [0 for i in range(len(zero)+1)]
a2[1] = zero[0]+one[0]
for i in range(2,len(zero)):
    a2[i] = a2[i-1]+zero[i-1]+one[i-1]
a2[len(zero)] = a2[len(zero)-1]+zero[len(zero)-1]

def sumArea(l,r):
    if l == 0:
        return a2[r]-a2[l]
    else:
        return a2[r]-a2[l]+one[l-1]

if len(zero)-k+1 < 1:
    print(len(s))
    sys.exit()
ans = 0
for i in range(len(zero)-k+1):
    ans = max(ans, sumArea(i,i+k))
print(ans)

Measured memory_bytes: 84324
import Data.Array
import Data.Array.ST

main = do
    list <- getContents
    let nums = map (read :: String -> Int).lines $ list
        arr  = addNums nums
    mapM_ print $ findModeValue arr

modifyArray a i f = fmap f (readArray a i) >>= writeArray a i

addNums :: [Int] -> Array Int Int
addNums list = runSTArray $ do
    arr <- newArray (1,100) 0
    mapM_ (\i -> modifyArray arr i (+1)) list
    return arr

findModeValue arr = find' arr 0 [] ixs
    where ixs = range.bounds $ arr

find' _   _  mvals [] = reverse mvals
find' arr mx mvals (x:xs)
    | arr ! x >  mx = find' arr (arr ! x) [x] xs
    | arr ! x == mx = find' arr mx (x:mvals) xs
    | arr ! x <  mx = find' arr mx mvals xs

Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y,z;
  cin >> x >> y;
  z = x + y;
  
  if (z % 2 == 0){
    cout << z/2 << endl;
  }
  
  else{
    cout << (z+1)/2 << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <ctime>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
  	cin >> n;
  	ll mod = 1000000007;
  	vector<ll> a(n), suf(n);
  	for (int i = 0; i < n; i++)
    	cin >> a[i];
  	suf[n - 1] = a[n - 1];
  	for (int i = n - 2; i >= 0; i--) {
    	suf[i] = suf[i + 1] + a[i];
      	suf[i] %= mod;
    }
  	ll ans = 0;
  	for (int i = 1; i < n; i++) {
      	ans += a[i - 1] * suf[i];
      	ans %= mod;
    }
  	cout << ans;
    return 0;
}

Measured memory_bytes: 6364
S = input()
a = int(S[:2])
b = int(S[2:])
if 1 <= a <= 12:
    if 1 <= b <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= b <= 12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 2940
n = int(input())
ans = 0
for i in range(1,n+1):
    if str(i)[-1] == "0":
        pass
    elif i < 10:
        ans += 1
    elif i <= 100:
        if str(i)[0] == str(i)[-1]:
            ans += 3
        elif int(str(i)[0]) > int(str(i)[1]):
            ans += 2
    elif i <= 1000:
        if str(i)[0] == str(i)[-1]:
            ans += (int(str(i)[1])+3)*2-1
        elif int(str(i)[0]) > int(str(i)[-1]):
            ans += 22
        elif int(str(i)[0]) < int(str(i)[-1]):
            ans += 2
    elif i <= 10000:
        if str(i)[0] == str(i)[-1]:
            ans += (int(str(i)[1:3]) + 13)*2-1
        elif int(str(i)[0]) > int(str(i)[-1]):
            ans += 222
        elif int(str(i)[0]) < int(str(i)[-1]):
            ans += 22
    elif i <= 100000:
        if str(i)[0] == str(i)[-1]:
            ans += (int(str(i)[1:4]) + 113)*2-1
        elif int(str(i)[0]) > int(str(i)[-1]):
            ans += 2222
        elif int(str(i)[0]) < int(str(i)[-1]):
            ans += 222
    elif i <= 1000000:
        if str(i)[0] == str(i)[-1]:
            ans += (int(str(i)[1:5]) + 1113)*2-1
        elif int(str(i)[0]) > int(str(i)[-1]):
            ans += 22222
        elif int(str(i)[0]) < int(str(i)[-1]):
            ans += 2222
print(ans)


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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  if(A.back() == B[0] && B.back() == C[0]){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, -1, sizeof(mat))
typedef long long ll;
int N; 
ll memo[2222][2222][2];
ll A[2222];
// who == 1 ? IOI : JOI 
ll calc(int l, int r, int who) {
  l = (l + N) % N;
  r = (r + N) % N;
  if(memo[l][r][who] != -1) return memo[l][r][who];
  if(l == r) return who ? 0 : A[l];
  ll ret = 0;
  if(who) {
    ret = A[l] > A[r] ? calc(l - 1, r, who ^ 1) : calc(l, r + 1, who ^ 1);
  } else {
    ret = max(calc(l - 1, r, who ^ 1) + A[l], calc(l, r + 1, who ^ 1) + A[r]);
  }
  return memo[l][r][who] = ret;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  CLR(memo);
  FOR(i,0,N) cin >> A[i];
  ll ans = 0;
  // ?????????i?????¨???
  FOR(i,0,N) {
    ans = max(ans, A[i] + calc(i - 1, i + 1, 1));
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    ll num = 1000000000 + 7;
    ll n; cin >> n;
    int x = n;
    n = 1;
    for(int i = 2; i <= x; i++){
        n = n * i;
        n = n % num;
//        cout << n << endl;
    }    
    cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double llf;
typedef std::pair<int,int> pii;
#define xx first
#define yy second
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const int MOD = 1e9 + 7;

//unsigned seed = chrono::system_clock::now().time_since_epoch().count();
//mt19937 rng (seed);


int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  vector<int> x = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << x[k-1] << endl;


  
}

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

#define vi vector<int>
#define all(v) v.begin(),v.end()
#define ll long long int
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD=1e9+7;

void solve(){
   string s;
   cin >> s;
   cout << s.substr(0,5);
   cout << ' ';
   cout << s.substr(6,7);
   cout << ' ';
   cout << s.substr(6+7+1);
}


int main(){
  IOS
     solve();
}
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

int N, W;
int w0;
int w[100];
int v[100];
int dp[100 + 1][300 + 1][100 + 1];
int ERROR = -1000000000000;
int INIT =  -10000000000000000;

int func(int i, int j, int k) //i番目までのものを使って強度の総和がj以下となるように選ぶ、ただし全部でk個使う
{
	if (k < 0)
	{
		return ERROR;
	}
	if (i < 0 && k > 0)
	{
		return ERROR;
	}
	if (i < 0)
	{
		return 0;
	}
	if (j < 0)
	{
		return ERROR;
	}
	if (dp[i][j][k] > INIT)
	{
		return dp[i][j][k];
	}
	if (j < w[i])
	{
		return func(i - 1, j, k);
	}

	int a = func(i - 1, j, k);
	int b = func(i - 1, j - w[i], k - 1) + v[i];
	int res = MAX(a, b);
	dp[i][j][k] = res;
	return res;
}

signed main()
{
	cin >> N >> W;
	for (int i = 0; i < N; i++)
	{
		cin >> w[i] >> v[i];
	}

	for (int i = 0; i < 101; i++)
	{
		for (int j = 0; j < 301; j++)
		{
			for (int k = 0; k < 101; k++)
			{
				dp[i][j][k] = INIT;
			}
		}
	}

	w0 = w[0];

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

	int ans = 0;
	for (int i = 0; i <= N; i++)
	{
		ans = MAX(ans, func(N - 1, MIN(3 * N, W - i * w0), i));
	}
	cout << ans << endl;
}


Measured memory_bytes: 24192
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int n, k;
  cin >> n >> k;
  if((n + 1) / 2 < k)
    cout << "NO";
  else
    cout << "YES";
  cout << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		VVI dp(N, VI(2));
		dp[0][0] = A[0];
		dp[0][1] = -A[0];
		RANGE(i, 1, N) {
			maxUpdate(dp[i][0], A[i]+dp[i-1][0]);
			maxUpdate(dp[i][1], -A[i]+dp[i-1][0]);
			maxUpdate(dp[i][0], -A[i]+dp[i-1][1]);
			maxUpdate(dp[i][1], A[i]+dp[i-1][1]);
		}
//		DD(dp);
		cout<<dp[N-1][0]<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
using namespace std;
int main() {
	int n, m, l;
	long m_a[100][100] = { 0 };
	long m_b[100][100] = { 0 };
	long m_res[100][100] = { 0 };

	cin >> n >> m >> l;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> m_a[i][j];

	for (int i = 0; i < m; i++)
		for (int j = 0; j < l; j++)
			cin >> m_b[i][j];

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			for (int x = 0; x < m; x++)
				m_res[i][j] += m_a[i][x] * m_b[x][j];
			cout << m_res[i][j];
			if (j < l - 1)
				cout << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 3312
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		int H = Integer.parseInt(scan.next());
		int A = Integer.parseInt(scan.next());
		int num = 0;
		if(H % A == 0) {
			num = H / A;
		} else { 
			num = H / A + 1; 
		}
		System.out.println(num);
	}
}

Measured memory_bytes: 22612
#include <iostream>
using namespace std;
int p[10000];
int main()
{
  int n,max=0,cijena=0,kraj;
  cin >> n;
  for(int i=0;i<n;i++)
  {
    cin >> p[i];
    cijena=cijena+p[i];
    if (p[i]>max)
      max=p[i];
    kraj=cijena-(max/2);
  }
  cout << kraj;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int main(){

	int x, y;
	cin >> x >> y;

	int flg = 0;
    int flg2 = 0;
	if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) flg = 0;
	else if(x == 2) flg = 2;
	else flg = 3;


	if(y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) flg2 = 0;
	else if(y == 2) flg2 = 2;
	else flg2 = 3;

	if(flg == flg2) cout << "Yes" << endl;
	else cout << "No" << endl;




}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    
    int ans = 0;
    for(int i = 1; i <= n; i++)
        if (a[a[i]] == i)
            ans++;
    ans /= 2;
    cout << ans << '\n';
  
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int a = Integer.parseInt(br.readLine());
        int b = Integer.parseInt(br.readLine());
        int c = Integer.parseInt(br.readLine());
        int x = Integer.parseInt(br.readLine());
        int ans = 0;
        
        for(int i = 0; i <= a; i++){
            for(int j = 0; j <= b; j++){
                for(int k = 0; k <= c; k++){
                    if(x == 500 * i + 100 * j + 50 * k){
                        ans++;
                    }
                }
            }
        }
        
        out.println(ans);
        out.close();
        
    }
}

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

int main(void){
    // Your code here!
    int n;
    cin>>n;
    string s;
    cin>>s;
    //int ct=0;
    
    long long int a=0,b=0,c=0;
    for(int i=0;i<s.size();i++){
      if(s[i]=='R') a++;
      else if(s[i]=='G') b++;
      else if(s[i]=='B') c++;
    }
    
    long long int sum = a*b*c;
    
    for(long long int i=1;i<n;i++){
      for(long long int j=i;j+i<n;j++){
        if(s[j-i]!=s[j] && s[j]!=s[j+i] && s[j-i]!=s[j+i]) sum--;
      }
    }
    
    //cout<<ct<<endl;
    //cout<<sum<<endl;
    cout<<sum<<endl;
}


Measured memory_bytes: 3616
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  string S;

  cin >> S;

  if (S[0] == S[2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
long comb(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
using namespace std;

int main(){
  int k,x;
  std::cin>>k>>x;
  int mi,ma;
  mi=max(x-k+1,-1000000);
  ma=min(1000000,x+k-1);
  for(int i=mi;i<=ma;i++)
    std::cout << i << std::endl;
  
}

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

int main() {
	int x,n;
	cin>>x>>n;
	int arr[n];
	int crr[102]={0};
	int k;
	for(int i=0;i<n;i++){
		cin>>k;
		crr[k]++;
	}
	int ans =1001;
	int ans1 = 0;
	for(int i=0;i<=101;i++){
		if(crr[i]==0){
		if(abs(i-x)<ans){
		  ans=abs(i-x);
		  ans1=i;
		}
		}
	}
	cout<<ans1<<endl;
	
}

Measured memory_bytes: 3620
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

    divisors.sort()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7

s = list(map(int, list(input())))
tmp = sum(s)
if tmp%9 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 92808
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

long gcd(long a,long b){
  if(a < b) swap(a,b);
  long r = a % b;
  while(r > 0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(){
  long n,x;
  cin >> n >> x;
  long tmp;
  vector<long> y(n);
  rep(i,n){
    cin >> tmp;
    y.at(i) = abs(x-tmp);
  }
  long d = y.at(0);
  for(int i=1;i<n;i++){
    d = gcd(d,y.at(i));
  }
  cout << d << endl;
}


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

int main(){
  char X, Y;
  cin >> X >> Y;
  
  if(X == 'A'){
    X = 10;
  }
  if(Y == 'A'){
    Y = 10;
  }
  if(X == 'B'){
    X = 11;
  }
  if(Y == 'B'){
    Y = 11;
  }
  if(X == 'C'){
    X = 12;
  }
  if(Y == 'C'){
    Y = 12;
  }
  if(X == 'D'){
    X = 13;
  }
  if(Y == 'D'){
    Y = 13;
  }
  if(X == 'E'){
    X = 14;
  }
  if(Y == 'E'){
    Y = 14;
  }
  if(X == 'F'){
    X = 15;
  }
  if(Y == 'F'){
    Y = 15;
  }

  if(X < Y){
    cout << "<" << endl;
  }
  else if(X > Y){
    cout << ">" << endl;
  }
  else if(X == Y){
    cout << "=" << endl;
  }
}
  

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int COUNT(vector<long long>A){
    int count=0;
    sort(A.begin(), A.end());
    for(int i=0; A[i]<0; i++){
        count++;
    }
    return count;
}


int main(){
    int N; cin >> N;
    vector<long long>A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    long long min=1000000000;
    long long res=0;
    int count = COUNT(A);
    for(int i=0; i<N; i++){
            res += abs(A[i]);
            min = (abs(A[i])<min?abs(A[i]):min);
    }
    
    if(count%2!=0){
        res-=2*min;
    }
    
    cout << res << endl;

    
}

Measured memory_bytes: 1792
// **** WHEN THE GOING GETS TOUGH, THE TOUGH GETS GOING. ****

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
typedef vector<ii> vii;
typedef vector<lii> lvii;

#define min_prq(t) priority_queue<t,vector<t>,greater<t>>
#define max_prq(t) priority_queue<t>
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------


signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n;
	cin>>n;
	ll ans1=0,ans2=0;
	ll last=0;
	lvi a(n+2,0);
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		ans1+=abs(a[i]-last);
		last=a[i];
	}
	ans1+=(abs(a[n+1]-last));
	last=0;
	for(int i=1;i<=n;i++)
	{
		ans2=ans1;
		ans2-=(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]));
		ans2+=abs(a[i+1]-a[i-1]);
		cout<<ans2<<endl;
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
 
int main()
{
    int n,k;
    cin >> n >> k;

    map<int,int> mp;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        mp[a]++;
    }

    vector<int> a;
    for(auto x: mp) a.emplace_back(x.second);
    sort(a.begin(),a.end());

    ll ans = 0;
    if(a.size() > k){
        for(int i = 0; i < a.size()-k; i++) ans += a[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll ans = 0; ll N;

void dfs( bool f3, bool f5, bool f7, ll now){
  if( now > N){ return ;}
  if( f3 && f5 && f7 && now <= N){ ans++;}
  
  dfs(true, f5, f7, 10*now+3); //末尾に3をつける
  dfs(f3, true, f7, 10*now+5);
  dfs(f3, f5, true, 10*now+7);
  return;
}
    
  
  




int main(){
   cin >> N;
  dfs(false,false,false,0LL);
  cout << ans << endl; return 0;}

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

int main() {
  int n, i, count;
  int a[200] = { 0 };
  int result = 100;
  
  cin >> n;
  
  for(i = 0; i < n; i++)
    cin >> a[i];
  
  for(i = 0; i < n; i++)
  {
    count = 0;
    while(a[i] % 2 == 0)
    {
      a[i] /= 2;
      count++;
    }
    
    if(result > count)
      result = count;
  }
  
  cout << result << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int m[22][22],i,j,n,a,b,t,M,R;
int s(int p)
{
	int i,res=0;
	for(i=0;i<n;i++)
		if(m[p][i]>0)
		{
			m[i][p]=0;
			res=res<m[p][i]+s(i)?m[p][i]+s(i):res;
		}
	return res;
}
int main()
{
	for(;scanf("%d",&n),n;)
	{
		memset(m,0,sizeof(m));
		for(i=R=M=0;i<n-1;i++)
		{
			scanf("%d%d%d",&a,&b,&t);
			a--,b--;
			R+=m[a][b]=m[b][a]=t;
		}
		for(i=0;i<n;i++)
		{
			for(j=a=0;j<n;j++)
				if(m[i][j]!=0)
					a++,t=j;
			if(i!=0&&a==1)
			{
				R-=m[i][t];
				m[i][t]=m[t][i]=-1;
			}
		}
		int tmp=s(0);
		printf("%d\n",2*R-s(0));
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep (i, n) cin >> a[i];
    sort(all(a), [](int a, int b) {return a > b;});
    rep (i, n) eprintf("%d ", a[i]); eprintf("\n");
    vector<int> numa(2 * a[0] + 2);
    rep (i, n) numa[a[i]]++;
    reprev (i, a[0] + 1) numa[i] += numa[i + 1]; 
    // rep (i, a[0] + 1) eprintf("%d ", numa[i]); eprintf("\n");
    int ok = 1, ng = a[0] * 2 + 1;
    while (ng - ok > 1) {
        int med = (ng + ok) / 2;
        ll count = 0;
        rep (i, n) count += numa[max(0, med - a[i])];
        if (count >= m) ok = med;
        else ng = med;
    }
    eprintf("ok=%d, ng=%d\n", ok, ng);
    ll ans = 0;
    vector<ll> suma(n + 1);
    rep (i, n) suma[i + 1] = suma[i] + (ll)a[i];
    rep (i, n) {
        int num = numa[max(0, ok - a[i])];
        eprintf("%d ", num);
        ans += num * (ll)a[i] + suma[num];
    }
    eprintf("\n");
    ll count_ok = 0;
    rep (i, n) count_ok += numa[max(0, ok - a[i])];
    eprintf("m=%lld, count_ok=%lld\n", m, count_ok);
    ans -= (ll)ok * (count_ok - m);
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2176
#include <cstdio>
#include <random>
using namespace std;

random_device rd;
mt19937 mt(rd());

template <class T>
struct tree
{
	struct node
	{
		T v;
		int c, p;
		node *n[2];

		node(T x)
		{
			v = x;
			c = 1;
			p = mt();
			n[0] = n[1] = nullptr;
		}
	};

	typedef node N;
	N *root;
	long counter;

	tree()
	{
		root = nullptr;
		counter = 0;
	}

	inline int count(N *n) {return n ? n->c : 0;}

	N* rotate(N* r, int b) 
	{
		N *s = r->n[1 - b];

		r->c += count(s->n[b]) - count(r->n[1 - b]);
		r->n[1 - b] = s->n[b];

		s->c += r->c - count(s->n[b]);
		s->n[b] = r;
		return s;
	}

	N* insert(int x, N *t, int cnt)
	{
		if (!t) {
			counter += cnt;
			return new N(x);
		}
		int b = !(x < t->v);
		if (b)
			cnt -= 1 + count(t->n[0]);
		t->n[b] = insert(x, t->n[b], cnt);
		t->c++;
		return rotate(t, 1 - b);
	}

	void insert(T x)
	{
		root = insert(x, root, count(root));
	}
};

int main()
{
	int	n, x;
	scanf("%d", &n);

	tree<int> t;
	while (n--) {
		scanf("%d", &x);
		t.insert(x);
	}

	printf("%ld\n", t.counter);
}



Measured memory_bytes: 12952
s = input()

s11 = int(s[0:2])
s12 = int(s[2:5])

if (1 <= s11) and (s11 <= 12) and (1 <= s12) and (s12 <= 12) :
    print("AMBIGUOUS")
elif (1 <= s11) and (s11 <= 12) :
    print("MMYY")   
elif (1 <= s12) and (s12 <= 12) :
    print("YYMM")    
else:
    print("NA")

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc169/tasks/abc169_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll A;
  ld B;
  cin >> A >> B;

  ll res = (A * 100 * B + 0.5) / 100;
  cout << res << "\n";
}


Measured memory_bytes: 3792
N = int(input())
A_list = [int(i) for i in input().split()]
B_list = [int(i) for i in input().split()]
C_list = [int(i) for i in input().split()]

satisfying = 0
prev_dish = A_list[0]
for i in range(N) :
    current_dish = A_list[i]
    satisfying += B_list[current_dish-1]
    # print("get", B_list[current_dish-1])

    if (prev_dish + 1 == current_dish) :
        satisfying += C_list[current_dish-2]
        # print("additional get",C_list[current_dish-2])

    prev_dish = current_dish

print(satisfying)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    ll N, x; cin >> N >> x;
    vector<ll> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    ll ans = (1LL<<60);
    ll b[N][N];

    for(int i=0; i<N; i++) b[i][0] = a[i];
    for(int i=0; i<=N-1; i++) for(int k=1; k<=N-1; k++) b[i][k] = min(b[i][k-1], a[(i+N-k)%N]);

    for(int k=0; k<=N-1; k++){
        ll tmp = k*x;
        for(int i=0; i<N; i++) tmp += b[i][k];
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;
  long long ans = 0, dp[2][2019] = {};
  int k = 0;
  for (auto c : s) {
    auto d = c - '0';
    for (int j = 0; j < 2019; j++) dp[k][(j * 10 + d) % 2019] = dp[k ^ 1][j];
    dp[k][d]++;
    ans += dp[k][0];
    k ^= 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3764
const s = require('fs').readFileSync('/dev/stdin','utf8').trim().split('')
const n = s.length
const blocks = s.join('').match(/(R+)|(L+)/g)

const numbers = []
for(var i in blocks) {
  var char = blocks[i][0]

  if(char === 'R') {
    for(var j=0;j<blocks[i].length-1;j++) {
      numbers.push(0)
    }

    var num = (blocks[i].length + blocks[i].length % 2) / 2
    numbers.push(num)
    num = (blocks[i].length - blocks[i].length % 2) / 2
    numbers.push(num)
  } else {
    var num = (blocks[i].length - blocks[i].length % 2) / 2
    numbers[numbers.length-2] += num
    num = (blocks[i].length + blocks[i].length % 2) / 2
    numbers[numbers.length-1] += num

    for(var j=0;j<blocks[i].length-1;j++) {
      numbers.push(0)
    }
  }
}

const answer = numbers.join(' ')
console.log(answer)


Measured memory_bytes: 19772
n = gets.to_i
min = last = gets.to_i
profits = []
(n-1).times{
  current = gets.to_i
  catch(:next) do
    if (current <= min)
      profits<<(current-last) if (profits.bsearch{|i| i >= 0} == nil)
      min = current
      throw :next
    end
    profits<<(current-min) if (current > last)
  end
  last = current
}
puts profits.max

Measured memory_bytes: 9708