akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <string>

using namespace std;

#define U unsigned
#define S short
#define L long
#define LL long long 
#define LLU long long unsigned

//Reading and Printing Arrays

//short int
#define rhd(arr, n) for(int aab = 0; aab < n; aab++){scanf("%hd", &arr[aab]);}
#define phd(arr, n) for(int aab = 0; aab < n; aab++){printf("%hd ", arr[aab]);}
//int
#define rd(arr, n) for(int aab = 0; aab < n; aab++){scanf("%d", &arr[aab]);}
#define pd(arr, n) for(int aab = 0; aab < n; aab++){printf("%d ", arr[aab]);}
//unsigned int
#define ru(arr, n) for(int aab = 0; aab < n; aab++){scanf("%u", &arr[aab]);}
#define pu(arr, n) for(int aab = 0; aab < n; aab++){printf("%u ", arr[aab]);}
//long int
#define rld(arr, n) for(int aab = 0; aab < n; aab++){scanf("%ld", &arr[aab]);}
#define pld(arr, n) for(int aab = 0; aab < n; aab++){printf("%ld ", arr[aab]);}
//unsigned long int
#define rlu(arr, n) for(int aab = 0; aab < n; aab++){scanf("%lu", &arr[aab]);}
#define plu(arr, n) for(int aab = 0; aab < n; aab++){printf("%lu ", arr[aab]);}
//long long int
#define rlld(arr, n) for(int aab = 0; aab < n; aab++){scanf("%lld", &arr[aab]);}
#define plld(arr, n) for(int aab = 0; aab < n; aab++){printf("%lld ", arr[aab]);}
//unsigned long long int
#define rllu(arr, n) for(int aab = 0; aab < n; aab++){scanf("%llu", &arr[aab]);}
#define pllu(arr, n) for(int aab = 0; aab < n; aab++){printf("%llu ", arr[aab]);}
//float
#define rf(arr, n) for(int aab = 0; aab < n; aab++){scanf("%f", &arr[aab]);}
#define pf(arr, n) for(int aab = 0; aab < n; aab++){printf("%f ", arr[aab]);}
//double
#define rlf(arr, n) for(int aab = 0; aab < n; aab++){scanf("%lf", &arr[aab]);}
#define plf(arr, n) for(int aab = 0; aab < n; aab++){printf("%lf ", arr[aab]);}
//char
#define rc(arr, n) for(int aab = 0; aab < n; aab++){scanf("%c", &arr[aab]);}
#define pc(arr, n) for(int aab = 0; aab < n; aab++){printf("%c", arr[aab]);}
//string
#define rs(arr) scanf("%s", arr);
#define ps(arr) puts(arr);

//swap
#define swap(a, b, tip) tip tempswap = a;a = b;b = tempswap;
//freopen
#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

/*       ▄▀▄     ▄▀▄
        ▄█░░▀▀▀▀▀░░█▄
    ▄▄  █░░░░░░░░░░░█  ▄▄
   █▄▄█ █░░▀░░┬░░▀░░█ █▄▄█       */

int min(int a, int b){	return a <= b ? a : b;}
int max(int a, int b){	return a >= b ? a : b;}
int findmin(long long arr[], long long n){int min = 0;for(int i = 1; i < n;min = arr[i] < arr[min] ? i : min, i++);return min;}
int findmax(long long int arr[], long long int n){int max = 0;for(int i = 1; i < n;max = arr[i] > arr[max] ? i : max, i++);return max;}
long long int arrsum(long long arr[], long long int n){long long int sum = 0;for(int i = 0; i < n; sum += arr[i], i++);return sum;}
	
int main(){

	int k, n;
  
	scanf("%d %d", &k, &n);

	int arr[n];
	LL aralik[n];

	rd(arr, n);

	for(int i = 0; i < n - 1; i++){
		aralik[i] = arr[i + 1] - arr[i];
	}

	aralik[n - 1] = arr[0] + (k - arr[n - 1]);

	int max = findmax(aralik, n);

	printf("%lld", arrsum(aralik, n) - aralik[max]);
}

Measured memory_bytes: 2560
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = deque(list(map(int, input().split())))

cnt = 0
cnt_max = 0

t = 0

#aの本を全部読む場合を考える
#bを1冊ずつ増やしたときに最大になるかどうかを判定する

c = []

for i in a:
  t += i
  if t <= k:
    c.append(i)
    cnt += 1
  else:
    t -= i
    break

#print(c)
cnt_max = cnt
tmp_cnt = cnt

t_max = t

c.reverse()
for i in range(len(c) + 1):
  d = []
  
  if i == 0:
    pass
  else:
    t_max -= c[i-1]
    tmp_cnt -= 1
    
  #print(i, t_max, tmp_cnt, c[i-1])
  
  t = t_max
  cnt = tmp_cnt
  
  for j in b:
    t += j
    #print('j:', j, t)
    if t <= k:
      cnt += 1
      d.append(j)
      t_max = t
      if cnt > cnt_max:
        cnt_max = cnt
        #print('cnt', cnt, 'max', cnt_max)
    else:
      break
      
  for i in range(len(d)):
    b.popleft()
    tmp_cnt += 1
      
print(cnt_max)
        


Measured memory_bytes: 128980
#include<stdio.h>
long long a[1000000],b[1000000];
int main()
{
    long long k,n,x,y,i,s;
    
    scanf("%lld%lld",&k,&n);
    s=k;
    for(i=0;i<n;i++)
    {
    scanf("%lld",&a[i]);
    }


    for(i=0;i<n;i++)
    {
    if(i==0)
    x=a[n-1]-a[i];
    else 
    x=k-(a[i]-a[i-1]);
    if(i==(n-1))
    y=a[n-1]-a[0];
    else
    y=k-(a[i+1]-a[i]);
    if(x<=y)
    b[i]=x;
    else
    b[i]=y;
  
    }
    for(i=0;i<n;i++)
    {
    if(b[i]<s)
    s=b[i];
    }
    printf("%lld",s);
}

Measured memory_bytes: 5760
#include<iostream>
#include<vector>
#include<math.h>

using namespace std;

int main(int argc, char **argv) {
    int n, t, a, ans;
    double diff;
    vector<double> h;

    cin >> n >> t >> a;

    for (int i = 0; i < n;i++) {
        int input;
        cin >> input;
        h.push_back(input);
        h[i] = t - h[i] * 0.006;
    }

    diff = fabs((double)a - h[0]);
    ans = 1;

    for (int j = 0; j < n; j++) {
        if (fabs((double)a - h[j]) < diff) {
            diff = fabs((double)a - h[j]);
            ans = j + 1;
        }
    }

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

Measured memory_bytes: 256
r, c = map(int, input().split())
matrix = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
    a = list(map(int, input().split()))
    for j in range(c):
        matrix[i][j] = a[j]
    matrix[i][c] = sum(a)
for l in range(c+1):
    for m in range(r):
        matrix[r][l] += matrix[m][l]

for cv in range(r+1):
    for fv in range(c+1):
        print(matrix[cv][fv], end='')
        if fv != c:
            print(" ", end='')
    print()


Measured memory_bytes: 6744
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

const int mod=1000000007;
struct mint{
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const{return mint(-x);}
  mint& operator+=(const mint a){
    if((x+=a.x)>=mod) x-=mod;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x+=mod-a.x)>=mod) x-=mod;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=mod;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a=pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }

  // for prime mod
  mint inv() const{
    return pow(mod-2);
  }
  mint& operator/=(const mint a){
    return (*this)*=a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

ll rui(ll a,ll n){
  if(n==0) return 1;
  ll aa=a;
  while(n!=1){
    a*=aa;
    a%=MOD;
    n--;
  }
  return a;
}

int main(){
  int N; cin >> N;
  vector<ll> c(N);
  rep(i,N) cin >> c[i];
  sort(all(c));
  mint A=rui(4,N-1);
  mint B=0;
  for(int i=0;i<N;i++){
    B+=c[i]*(N+1-i);
  }
  mint ans=A*B;
  cout << ans.x << endl;
}

Measured memory_bytes: 1792
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

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


int main()
{
    
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X),B(Y),C(Z);
//    vector<ll> buono(pow(K,3));
    vector<ll> buono;
    
    for(int i=0;i<X;i++) cin >> A[i];
    for(int i=0;i<Y;i++) cin >> B[i];
    for(int i=0;i<Z;i++) cin >> C[i];
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());
    
//    int p=0;
    for(int i=0;i<X;i++)
    {
        for(int j=0;j<Y;j++)
        {
            for(int k=0;k<Z;k++)
            {
                if((i+1) * (j+1) * (k+1) > K) break;
//                buono[p] = A[i] + B[j] + C[k];
//                p++;
                buono.push_back(A[i] + B[j] + C[k]);
            }
        }
    }
    
//    sort(buono.begin(), buono.begin() + p - 1, greater<ll>());
    sort(buono.begin(), buono.end(), greater<ll>());
    
    for(int i=0;i<K;i++) cout << buono[i] << endl;
    
    return 0;
}


Measured memory_bytes: 1404
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 100001
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
bool f[N];
int n;
int cnt,head[N],nxt[N+N],to[N+N];
void dfs(int u,int fa)
{
	for(int i=head[u],v;i;i=nxt[i])
		if((v=to[i]) != fa)
		{
			dfs(v,u);
			if(!f[v])
			{
				if(!f[u])f[u]=f[v]=1;
				else puts("First"),exit(0);
			}
		}
}
int main()
{
	re(n);
	for(int i=1,u,v;i<n;++i)
	{
		re(u),re(v);
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,0);
	puts(f[1]?"Second":"First");
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i]) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3916
x, y, z, k = map(int, input().split())

a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

ab = []
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)

abc = []
for i in ab[:k]:
    for j in c:
        abc.append(i + j)
abc.sort(reverse=True)

for i in range(k):
    print(abc[i])

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

const int Max = 100;
const int Min = -100;

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	if((W > 0 && W <= Max) && (H > 0 && H <= Max) && (r > 0 && r <= Max)) 
	{ 
		if((0 <= (x-r)) && (0 <= (y-r)) && ((x+r) <= W) && ((y+r) <= H))	
	
			cout << "Yes";
		else 
			cout << "No";
		cout << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1156
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int a = x2 - x1;
	int b = y2 - y1;
	int x3 = x2 - b;
	int y3 = y2 + a;
	int x4 = x3 - a;
	int y4 = y3 - b;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << " " << endl;
	return 0;
}

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

int n;
std::vector<std::string> s;
std::unordered_map<std::string,int> hash;

void input(){
    std::cin>>n;
    s.resize(n);
    for(int i=0;i<n;i++)std::cin>>s[i];
}

int main(){
    input();
    for(int i=0;i<n;i++)std::sort(s[i].begin(),s[i].end());
    long long ans = 0;

    for(int i=0;i<n;i++){
        hash[s[i]]++;
        ans += hash[s[i]]-1;
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 17700
#include <stdio.h>
 
int main(void){
  int k,n,i;
  int a[200001] = {0};
  int distance = 0;
  int near = 100000000;
  
  do {
    scanf("%d ",&k);
  }while(k < 2 || k > 1000000);
  
  do {
    scanf("%d",&n);
  }while(n < 2 || n > 200000);
  
  
  for (i=1; i<n+1; i++) {
    do {
      scanf("%d ",&a[i]);
    }while(a[i] < a[i-1]);
  }
  
  for (i=1; i<n+1; i++) {
    if (i==1)
      distance = k - (k-a[n]+a[1]);
    else
      distance = k - (a[i]-a[i-1]);
    if (near > distance)
      near = distance;
  }
  
  printf("%d",near);
  
  return 0;
}

Measured memory_bytes: 2460
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int t,x;
    cin>>t>>x;

    cout<< (t+0.0)/x << endl;

    // cout << ans << endl;
    return 0;
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] n = Input.ScanIntArray();
          Array.Sort(n);
          if(n[0]==n[1])
            Console.WriteLine(n[2]);
          else
          Console.WriteLine(n[0]);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, K: int, h: "List[int]"):
    c = 0
    for i in range(N):
        if h[i]>=K:
            c+=1
    print(c)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21308
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int h[105];
int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> h[i];
	int ans = 0;
	for(int i=1;i<=100;i++){
		int f = 0;
		for(int j=0;j<N;j++){
			if(h[j]>=i&&f==0){
				ans++;
				f=1;
			}
			if(h[j]<i&&f==1)f=0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main() {
	int n, m;
	vector<int> v;

	while(cin >> n >> m) {
		v.push_back(n + m);
	}

	for(int i = 0; i < v.size(); i++) {
		cout << (int)log10((double)v[i]) + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3356
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    bool ok=1;
    rep(i,s.size()){
        if(s[i]!=t[i]) ok=0;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 3652
d[150][120];b,i,j,s,t,u,m,n,*p;main(a){for(;scanf("%d%d",&n,&m)*n;printf("%d\n",s)){for(memset(d,9,7e4);t=m--;d[a][b]=d[b][a]=i/100)scanf("%d,%d,%d",&a,&b,&i);for(s=i=1-n;i++;s+=d[n][t=u])for(d[j=u=n][t]=0;j--;*p&&d[n][u]>*p?u=j:0)p=d[n]+j,*p=fmin(*p,d[t][j]);}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
long long int b[200000],c[200000];
int main()
{
//freopen("input.txt","r",stdin);
long long int n,i,j,s=0;
cin>>n;
long long int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];}
//long long int a[n];
for(i=0;i<n;i++)
{
//cin>>a[i];
b[i]=a[i]+i;
if(i-a[i]>0){
c[i-a[i]]++;
}
}
//cout<<"Hello"<<endl;
for(i=0;i<n;i++)
{
if(b[i]<n)
s=s+c[b[i]];
}
cout<<s<<endl;

}


Measured memory_bytes: 8324
import java.util.Scanner;

public class Main { // https://atcoder.jp/contests/abc103/tasks/abc103_c
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		long res = 0;
		for (int i = 0; i < n; i++) {
			res += x.nextInt();
		}
		res -= n;
		System.out.println(res);
	}
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    int vote = 0;
    for (auto &&a : A) {
        cin >> a;
        vote += a;
    }

    int m = 0;
    for (auto a : A) {
        if ((double)vote / (4 * M) <= a) {
            m++;
        }
    }

    cout << (m < M ? "No" : "Yes") << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

int l;
long long base;
vector<long long> invaders;

void appearance() {
	invaders.push_back(l + base);
}

void move() {
	int d;
	scanf("%d", &d);

	base += d;

	vector<long long>::iterator en = upper_bound(invaders.begin(), invaders.end(), base);

	if(invaders.begin() != en) {
		printf("damage %d\n", (int)(en - invaders.begin()));
		invaders.erase(invaders.begin(), en);
	}
}

void rifle() {
	int k;
	scanf("%d", &k);

	if(invaders.size() >= k) {
		invaders.erase(invaders.begin() + (k - 1));
		puts("hit");
	}
	else
		puts("miss");
}

void grenade() {
	int r;
	long long x;
	scanf("%lld %d", &x, &r);

	x += base;
	vector<long long>::iterator it = lower_bound(invaders.begin(), invaders.end(), x - r);

	int cnt = 0;
	while(it != invaders.end() && *it <= x + r) {
		++cnt;
		it = invaders.erase(it);
	}

	printf("bomb %d\n", cnt);
}

void distance() {
	int k;
	scanf("%d", &k);

	if(invaders.size() >= k)
		printf("distance %lld\n", invaders[k - 1] - base);
	else
		printf("distance -1\n");
}

int main() {
	void (*operation[5])() = {&appearance, &move, &rifle, &grenade, &distance};

	for(int q; scanf("%d %d", &q, &l), q;) {
		base = 0;
		invaders.clear();

		for(int i = 0; i < q; ++i) {
			int in;
			scanf("%d", &in);
			(*operation[in])();
		}

		puts("end");
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1528
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;

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; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main() {
	int n, k;
	cin >> n >> k;
	Vi H(n);
	rep(i, n)  cin >> H[i];
	Vi dp(n, INT_MAX);
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i - j >= 0)  chmin(dp[i], dp[i - j] + abs(H[i] - H[i - j]));
		}
	}
	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
// C - A x B + C
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rp(i,s,e) for(ll i=(ll)(s);i<(ll)(e);++i)

int main(){
	ll n; cin>>n;
	ll cnt = 0;
	rp(a, 1, n){
		ll bn = (n-1) / a;
		rp(b, 1, bn+1){
			if(n - a*b <= 0) break;
			cnt++;
		}
	}
	cout<< cnt <<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#define MODD 1000000007
using namespace std;

long long dp[1000005][15];

int main()
{
	string s;
	cin >> s;
	
	if (s[0] == '?') {
		for (int i = 0; i < 10; i++) {
			dp[0][i] = 1;
		}
	} else {
		dp[0][s[0] - '0'] = 1;
	}
	
	int len = s.size();
	for (int i = 1; i < len; i++) {
		if (s[i] == '?') {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 13; k++) {
					dp[i][(k * 10 + j) % 13] += dp[i - 1][k];
					dp[i][(k * 10 + j) % 13] %= MODD;
				}
			}
		} else {
			for (int j = 0; j < 13; j++) {
				dp[i][(j * 10 + s[i] - '0') % 13] += dp[i - 1][j];
				dp[i][(j * 10 + s[i] - '0') % 13] %= MODD;
			}
		}
	}
	cout << dp[len - 1][5] << endl;
	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define p_b push_back
#define pll pair < ll , ll >
#define lt(v) v[v.size()-1]
#define fori(n) for( int i = 0; i < n; i++)
#define s second
#define f first
using namespace std;
ll M = 1000000007;
unordered_map < string , ll > mp;
int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for( int i = 0; i < n; i++)
    {
        string d;
        cin >> d;
        mp[d]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}


Measured memory_bytes: 3672
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

struct Info{
	int left,right;
};

struct Data{
	Data(){
		for(int i = 0; i < 100; i++)attend[i] = false;
	}

	Info info[100];
	bool attend[100];
};

int main(){

	char buf[12];
	int num_of_J;

	scanf("%d",&num_of_J);
	Info jyugyou[num_of_J];

	for(int i = 0; i < num_of_J; i++){
		scanf("%s",buf);
		jyugyou[i].left = (10*(buf[0]-'0')+buf[1]-'0')*60+(10*(buf[3]-'0')+buf[4]-'0');
		jyugyou[i].right = (10*(buf[6]-'0')+buf[7]-'0')*60+(10*(buf[9]-'0')+buf[10]-'0');
	}

	int N,K;
	scanf("%d",&N);

	Data teacher[N];

	for(int i = 0; i < N; i++){
		scanf("%d",&K);
		for(int a = 0; a < K; a++){
			scanf("%s",buf);
			teacher[i].info[a].left = (10*(buf[0]-'0')+buf[1]-'0')*60+(10*(buf[3]-'0')+buf[4]-'0');
			teacher[i].info[a].right = (10*(buf[6]-'0')+buf[7]-'0')*60+(10*(buf[9]-'0')+buf[10]-'0');

			for(int b = 0; b < num_of_J; b++){
				if(jyugyou[b].left > teacher[i].info[a].right)break;

				if(teacher[i].info[a].left <= jyugyou[b].left && teacher[i].info[a].right >= jyugyou[b].right){
					teacher[i].attend[b] = true;
				}
			}

		}
	}

	int M;
	scanf("%d",&M);

	Data student[M];
	for(int i = 0; i < M; i++){
		scanf("%d",&K);
		for(int a = 0; a < K; a++){
			scanf("%s",buf);
			student[i].info[a].left = (10*(buf[0]-'0')+buf[1]-'0')*60+(10*(buf[3]-'0')+buf[4]-'0');
			student[i].info[a].right = (10*(buf[6]-'0')+buf[7]-'0')*60+(10*(buf[9]-'0')+buf[10]-'0');

			for(int b = 0; b < num_of_J; b++){
				if(jyugyou[b].left > student[i].info[a].right)break;

				if(student[i].info[a].left <= jyugyou[b].left && student[i].info[a].right >= jyugyou[b].right){
					student[i].attend[b] = true;
				}
			}
		}
	}

	int maximum = 0,can_T,can_S;

	for(int i = 0; i < num_of_J; i++){
		can_T = can_S = 0;
		for(int a = 0; a < N; a++){
			if(teacher[a].attend[i])can_T++;
		}
		for(int a = 0; a < M; a++){
			if(student[a].attend[i])can_S++;
		}
		maximum += min(can_T,can_S);
	}

	printf("%d\n",maximum);

	return 0;
}

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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    int h, a;
    in(h);
    in(a);
    ll ans;
    if (h % a == 0)
    {
        ans = h / a;
    }
    else
    {
        ans = h / a + 1;
    }
    out(ans);
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    ll N, M; cin >> N >> M;
    set<ll> a;
    REP(i, M)
    {
        ll t; cin >> t;
        a.insert(t);
    }

    vll dp(N+1);
    dp[0] = 1;
    REP1(i, N)
    {
        if(i == 1) dp[i] = dp[i-1] % MOD;
        else dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        if(a.find(i) != a.end()) dp[i] = 0;
    }
    cout << dp[N] % MOD << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 5760
/*
	ID: sixathofpain
	TASK: friday
	LANG: C++   

*/


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#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 all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

int32_t main(){
    IOS;
	
    // freopen("friday.in","r",stdin);
    // freopen("friday.out","w",stdout);

    int  n;
    cin>>n;
    int ans = 1;
    ans = power(10,n,MOD);ans%=MOD;
    ans = ans-2*power(9,n,MOD)+power(8,n,MOD);ans%=MOD;ans+=MOD;ans%=MOD;
    cout<<ans<<endl;
    

    return 0;
}

Measured memory_bytes: 3660
#import collections
N,Q=map(int,input().split())
lc=[[] for i in range(N)]#二重リストで木を表現
for i in range(N-1):
    a,b=map(int,input().split())
    lc[a-1].append(b-1)
    lc[b-1].append(a-1)
lv=[0 for i in range(N)]#値のリスト
for i in range(Q):
    p,x=map(int,input().split())
    lv[p-1]+=x
lf=[0 for i in range(N)]#訪れたかどうか
#d=collections.deque([0])
lp=[0]
lf[0]=1
#for i in range(N):
while len(lp)>0:
    #p=lp[-1]
    p=lp.pop()
    for c in lc[p]:
        if lf[c]==0:
            lv[c]+=lv[p]
            lf[c]=1
            lp.append(c)
for i in range(N-1):
    print(lv[i],end=" ")
print(lv[N-1])


Measured memory_bytes: 52624
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n;
char returneki[60];
map<char,long long int>eki;

int main() {
    cin>>n;
	while(n!=0){
		string str;
		long long int len[50],tanka[10]={5,7,5,7,7},type=0;
		for(int i=0;i<n;i++){
			cin>>str;
			len[i]=str.length();
		}
		for(int i=0;i<n-4;i++){
			type=0;
			tanka[0]=5;
			tanka[1]=7;
			tanka[2]=5;
			tanka[3]=7;
			tanka[4]=7;
			for(int j=i;j<n;j++){
				tanka[type]-=len[j];
				if(tanka[type]==0){
					if(type<4){type++;}
					else{cout<<i+1<<endl;goto next;}
				}else if(tanka[type]<0){
					break;
				}
			}
		}
		next:
		cin>>n;
	}
	
} 



Measured memory_bytes: 3180
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

struct Player {
  int number;
  float rec;
  bool operator<(const Player& a) const { return rec < a.rec; }
};

int main() {
  vector<Player> v;
  rep (i,3) {
    Player players[8];
    rep (j,8) {
      cin >> players[j].number >> players[j].rec;
    }
    sort(players, players + 8);
    rep (j,2) {
      printf("%d %.2lf\n", players[j].number, players[j].rec);
    }
    v.push_back(players[2]);
  }
  sort(v.begin(), v.end());
  rep (i,2) {
    printf("%d %.2lf\n", v[i].number, v[i].rec);
  }
  return 0;
}

Measured memory_bytes: 0
h,w = map(int,input().split())

if h*w % 2 == 1 or 0 < h*w % 2 < 1:
    ans = (h*w//2) + 1
else:
    ans = h*w//2

if h > 1 and w == 1:
    ans = 1
elif w > 1 and h == 1:
    ans = 1

print(ans)


Measured memory_bytes: 2940
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T = lint>
struct Edge {
	int to;
	T cost;
	Edge() {}
	Edge(int to, T cost) : to(to), cost(cost) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

template<class T>
vector<T> Dijkstra(vector<vector<Edge<T>>> &edges, int st) {

	int V = (int)edges.size();
	const T inf = numeric_limits<T>::max() / 2;
	vector<T> cost(V, inf);
	cost[st] = 0;

	priority_queue<Edge<T>, vector<Edge<T>>, greater<Edge<T>>> p_que;
	p_que.emplace(st, cost[st]);

	while (!p_que.empty()) {

		Edge<T> now(p_que.top().to, p_que.top().cost);
		p_que.pop();

		if (cost[now.to] < now.cost) continue;
		for (const Edge<T> &e : edges[now.to]) {
			T tmp_cost = now.cost + e.cost;
			if (cost[e.to] > tmp_cost) {
				cost[e.to] = tmp_cost;
				p_que.emplace(e.to, cost[e.to]);
			}
		}
	}

	return cost; // min cost to vertex idx from st
}

template<class T>
inline bool chmin(T &a, T b) { return a > b && (a = b, true); }

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M, s, t;
	cin >> N >> M >> s >> t;
	s--, t--;

	vector<vector<Edge<lint>>> edge_yen(N), edge_snu(N);
	for (int i = 0; i < M; i++) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--, v--;
		edge_yen[u].emplace_back(v, a);
		edge_yen[v].emplace_back(u, a);
		edge_snu[u].emplace_back(v, b);
		edge_snu[v].emplace_back(u, b);
	}

	auto d_yen = Dijkstra(edge_yen, s);
	auto d_snu = Dijkstra(edge_snu, t);
	DMP(d_yen, d_snu);

	vector<lint> sum_cost(N);
	sum_cost.back() = d_yen.back() + d_snu.back();
	for (int i = N - 2; i >= 0; i--) sum_cost[i] = min(d_yen[i] + d_snu[i], sum_cost[i + 1]);

	for (int i = 0; i < N; i++) cout << mypow(10, 15) - sum_cost[i] << "\n";

	return 0;
}

Measured memory_bytes: 19016
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


// LRUD
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
// const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
// const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    int n, d;
    cin >> n >> d;
    double x[1000][1000];
    for (int i = 0; i < n; i++){
        for (int k = 0; k < d; k++){
            cin >> x[i][k];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            double dist = 0;
            for (int k = 0; k < d; k++){
                dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            // if (sqrt(dist) % 1 == 0) ans++;
            if (fmod(sqrt(dist), 1) == 0) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}






















Measured memory_bytes: 384
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, (input().split())))
tmp = sum(A)
root = 0
ans = 0
for i in range(N+1):
    if i==0:
        mx = 1
    else:
        mx = root*2
    if A[i] > mx:
        ans = -1
        break
    root = min(tmp, mx) - A[i]
    tmp -= A[i]
    ans += root + A[i]

print(ans)

Measured memory_bytes: 18936
class SegmentTree:
    def __init__(self, lst, op, e):
        self.n = len(lst)
        self.N = 1 << ((self.n - 1).bit_length())
        self.op = op # operation
        self.e = e # identity element
        self.v = self._build(lst) # self.v is set to be 1-indexed for simplicity
        
    def _build(self, lst):
        # construction of a tree
        # total 2 * self.N elements (tree[0] is not used)
        tree = [self.e] * (self.N) + lst + [self.e] * (self.N - self.n)
        for i in range(self.N - 1, 0, -1): tree[i] = self.op(tree[i << 1], tree[(i << 1)|1])
        return tree
    
    def __getitem__(self, i):
        return self.v[i + self.N]
    
    # update a_i to be x 
    def update(self, i, x):
        v, op = self.v, self.op
        i += self.N
        v[i] = x
        while i > 0:
            i >>= 1 # move to parent
            v[i] = op(v[i << 1], v[(i << 1)|1])
    
    # returns answer for the query interval [l, r)
    def fold(self, l, r):
        N, e, v, op = self.N, self.e, self.v, self.op
        left = l + N; right = r + N
        L = R = e
        while left < right:
            if left & 1: # self.v[left] is the right child
                L = op(L, v[left])
                left += 1
            if right & 1: # self.v[right-1] is the left child
                right -= 1
                R = op(v[right], R)
            left >>= 1; right >>= 1
        return op(L, R)

def wa(set1, set2):
    return set1 | set2

n = int(input())
s = input()
lst = []
for i in range(n):
    lst.append(set([s[i]]))

st = SegmentTree(lst, wa, set([]))

ans = []
q = int(input())
for i in range(q):
    que = input()
    if que[0] == '1':
        kind, i, c = que.split()
        i = int(i) - 1
        st.update(i, set([c]))
    else:
        kind, l, r = map(int, que.split())
        l -= 1
        ans.append(len(st.fold(l, r)))

for i in ans:
    print(i)

Measured memory_bytes: 375088
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(string line; getline(cin, line);) {
		istringstream is(line);
		stack<double> s;
		for(string ch; is >> ch;) {
			if(ch == "+") {
				double a = s.top();
				s.pop();
				double b = s.top();
				s.pop();
				s.push(b + a);
			} else if(ch == "-") {
				double a = s.top();
				s.pop();
				double b = s.top();
				s.pop();
				s.push(b - a);
			} else if(ch == "*") {
				double a = s.top();
				s.pop();
				double b = s.top();
				s.pop();
				s.push(b * a);
			} else if(ch == "/") {
				double a = s.top();
				s.pop();
				double b = s.top();
				s.pop();
				s.push(b / a);
			} else {
				istringstream iss(ch);
				double t; iss >> t;
				s.push(t);
			}
		}
		printf("%.6f\n", s.top());
	}
	return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

MOD = (10**9) + 7


def main():
    ans = 1
    N = int(input().strip())
    for n in range(1, N + 1):
        ans *= n
        ans = ans % MOD
    return ans


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	long long n, k;
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		long long a, b;
		cin >> a >> b;
		long long number = min(a, min(b, min(n+1 - a, n+1 - b))) % 3;
		if (number == 0) number = 3;
		cout << number << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;

int main() {
	long long  N;
	cin >> N;



	auto FactorialMod= [](long long  inN, long long inE) {
		long long  d = 0;
		long long  n = inN;
		
		while (inN>=inE)
		{
			d += inN / inE;
			inN = inN / inE;
		}

		return d;

	};



	if (N % 2 != 0)
	{
		cout << 0<< endl;

	}
	else
	{
		cout << FactorialMod(N / 2, 5) << endl;
	}





	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
    bool flg = 0;
    cin >> n;
    for(register int i = 1; i <= 9; ++i) for(register int j = 1; j <= 9; ++j) {
        if(i * j == n) {
            flg = 1; break;
        }
    }
    if(flg) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

using std::cin;
using std::cout;
using std::endl;

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int M = 3000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int n, m, ans = 0;
int lim[5];

inline bool check(int x) {
    if (!x) return n == 1 && (lim[1] == 0|| lim[1] == -1);
    int tmp = x, len = 0;
    while (tmp) len++, tmp /= 10;
    for (int i = len; i >= 1; i--, x /= 10) {
        if (x % 10 != lim[i] && lim[i] != -1) return false;
    }
    return len == n;
}

int main() {
    cin >> n >> m;
    memset(lim, -1, sizeof(lim));
    for (int i = 1; i <= m; i++) {
        int s, c;
        cin >> s >> c;
        if (lim[s] == -1) lim[s] = c;
        else if (lim[s] != c) ans = -1;
    }
    bool flag = false;
    if (ans != 0) {
        flag = true;
        printf("%d\n", ans);
    } else {
        for (int i = 0; i <= 999; i++) {
            if (check(i)) {
                printf("%d\n", i);
                flag = true;
                break;
            }
        }
    }
    if (!flag) puts("-1");
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<String>();
    let (s, t) = (v[0].clone(), v[1].clone());
    let v = read_vec::<i64>();
    let (a, b) = (v[0], v[1]);
    let u = read::<String>();
    if s == u {
        println!("{} {}", a - 1, b);
    } else {
        println!("{} {}", a, b - 1);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352