akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 7;

long long a[N];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort (a + 1, a + n + 1);
	int pnt = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] * 2 < a[i + 1])
			pnt = i + 1;
		a[i + 1] += a[i];
	}
	cout << n - pnt + 1;


	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	ll mn = 0 ;
	for(int i=0;i<5;i++){
		ll a ; cin >> a ;
		ll sub ;
		if(n%a==0) sub = n/a-1 ;
		else sub = n/a ;
		if(sub>mn) mn = sub ;
	}
	cout << mn+5 << endl ;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int w, h, n, x[10000] = { 0 }, y[10000] = { 0 }, ans = 0;
	cin >> w >> h >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	for (int i = 1; i < n; i++) {
		int ta = y[i] - y[i-1];
		int yo = x[i] - x[i-1];
		if (ta > 0 && yo > 0) {
			ans += ta + yo - min(ta, yo);
			//cout << ans << endl;
		}
		else if (ta < 0 && yo < 0) {
			ans += abs(ta) + abs(yo) - min(abs(ta), abs(yo));
		}
		else {
			ans += abs(ta) + abs(yo);
			//cout << ans << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3160
N, K = [int(INPUT) for INPUT in input().strip().split(' ')]

total_num = 0

for k in range(K, N + 2):
    # Min = sum(range(k))
    # Max = sum(range(N - (k - 1), N + 1))
    # # print("%s~%s" % (Min, Max))
    # num = Max - Min + 1
    num = (N - (k - 1)) * k + 1
    total_num += num

print(int(total_num % (1e9+7)))

Measured memory_bytes: 9180
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    

    void calc()
    {
        cin = new Scanner();
        string S = cin.next();
        int N = cin.nextInt();
        int[] A = new int[S.Length];
        for (int i = 0; i < S.Length; i++)
        {
            A[i] = S[i] - 'a';
        }

        for (int i = 0; i < S.Length; i++)
        {
            if((26 - A[i]) % 26 <= N)
            {
                N -= (26 - A[i]) % 26;
                A[i] = 0;
            }
        }
        A[S.Length - 1] += N;
        A[S.Length - 1] %= 26;
        for (int i = 0; i < S.Length; i++)
        {
            Console.Write((char)('a' + A[i]));
        }
        Console.WriteLine();
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13240
#include<stdio.h>

#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

void dijkstra(void){
	int minv,i,v;
	int d[MAX],color[MAX];

	for(i=0;i<n;i++){
		d[i]=INFTY;
		color[i]=WHITE;
	}
	int u;
	d[0]=0;
	color[0]=GRAY;
	while(1){
		minv=INFTY;
		u=-1;
		for(i=0;i<n;i++){
			if(minv>d[i] && color[i]!=BLACK){
				u=i;
				minv=d[i];
			}
		}
		if(u==-1)break;
		color[u]=BLACK;
		for(v=0;v<n;v++){
			if(color[v]!=BLACK && M[u][v] != INFTY){
				if(d[v]>d[u]+M[u][v]){
					d[v]=d[u]+M[u][v];
					color[v] = GRAY;
				}
			}
		}

	}
	for(i=0;i<n;i++){
		printf("%d %d\n",i,(d[i]==INFTY ? -1 : d[i]));
	}

}

int main(){
	int i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			M[i][j]=INFTY;
		}
	}

	int k,c,u,v;
	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d%d",&v,&c);
			M[u][v]=c;
		}
	}

	dijkstra();

	return 0;
}

Measured memory_bytes: 636
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp

months = [*1..12].map { |n| n.to_s.rjust(2, '0') }

if months.include?(S[0..1])
  if months.include?(S[2..])
    puts 'AMBIGUOUS'
  else
    puts 'MMYY'
  end
else
  if months.include?(S[2..])
    puts 'YYMM'
  else
    puts 'NA'
  end
end


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

int main(void){
    ll n, m;
    cin >> n >> m;
    priority_queue<ll, vector<ll>, greater<ll>> a;
    rep(i, n){
        ll tmp;
        cin >> tmp;
        a.push(tmp);
    }

    pair<ll, ll> cb[m];
    rep(i, m){
        cin >> cb[i].second >> cb[i].first;
    }

    sort(cb, cb + m, greater<pair<ll, ll>>());
    ll sum = 0;
    rep(i, m){
        rep(j, cb[i].second){
            if(a.top() < cb[i].first){
                a.pop();
                sum += cb[i].first;
                if(a.size() == 0){
                    cout << sum << endl;
                    return 0;
                }
            }else{
                break;
            }
        }
    }

    while(a.size()){
        sum += a.top();
        a.pop();
    }

    cout << sum << endl;
}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;


int main()
{
    string s;
    cin >> s;
    for (char c : s)
        if (c == '7')
            return cout << "Yes", 0;
    cout << "No";
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ls(x) x<<1
#define rs(x) x<<1|1
const int MN=100000+5;
const int P=1000000007;
using namespace std;
typedef long long ll;
template<typename T>inline T IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n;ll A,B;
ll f[MN],a[MN],t[MN*4];
void mod(int rt,int l,int r,int p,int d){
	t[rt]=(t[rt]+d)%P;
	if(l==r)return ;
	int mid=l+r>>1;
	if(p<=mid)mod(ls(rt),l,mid,p,d);
	else mod(rs(rt),mid+1,r,p,d);
}
int ask(int rt,int l,int r,int L,int R){
	if(L>R)return 0;
	if(L<=l&&r<=R)return t[rt];
	int mid=l+r>>1,res=0;
	if(L<=mid)res=(res+ask(ls(rt),l,mid,L,R))%P;
	if(mid+1<=R)res=(res+ask(rs(rt),mid+1,r,L,R))%P;
	return res;
}
void input(){
	IN(n),IN(A),IN(B);if(A<B)swap(A,B);
	for(int i=1;i<=n;++i)IN(a[i]);
	a[0]=-A,a[n+1]=a[n]+A;mod(1,0,n,0,f[0]=1);
	int l=0,r=0;
	for(int i=1;i<=n+1;i++){
		while(a[i]-a[r+1]>=A)r++;
		if(i>=2&&a[i-1]-a[i-2]<B)l=i-2;
		if(a[i]-a[i-1]>=A)f[i]=f[i-1];
		f[i]=(f[i]+ask(1,0,n,l,min(r,i-2)))%P;
		if(i<=n&&a[i+1]-a[i-1]>=B)mod(1,0,n,i,f[i]);
	}
	printf("%lld\n",f[n+1]);
}
int main(){
	
	input();
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
#define MOD (ll)(1e9+7)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m; cin>>n>>m;
	vector<int> a(n),b(m);
	for(auto &i:a) cin>>i;
	for(auto &i:b) cin>>i;
	vector<vector<int>> dp(n+1);
	for(auto &i:dp) i.resize(m+1);
	For(i,0,n) dp[i][0]=0;
	For(i,0,m) dp[0][i]=0;
	For(i,1,n)
	{
		For(j,1,m)
		{
			dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+MOD;
			if(a[i-1]==b[j-1]) dp[i][j]+=dp[i-1][j-1]+1;
			dp[i][j]%=MOD;
		}
	}
	cout<<(dp[n][m]+1)%MOD<<"\n";
	return 0;
}















Measured memory_bytes: 31616
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n = sys.stdin.readline().rstrip()

    if n[0] * 3 in n: ans = 'Yes'
    elif n [3] * 3 in n: ans = 'Yes'
    else: ans = 'No'
    print(ans)

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

n = inp()
print(int((n-1)*n//2))

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

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

int main() {

    int n;
    cin >> n;

    vector<int> a(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];

    int ans = 0;
    int count = 0;

    for(int i = 0; i < n - 1; ++i) {
        if(a[i] >= a[i + 1])
            count++;
        else
            count = 0;
        
        
        ans = max(count, ans);
    }


    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 640
s = sorted( list(input()) )
t = sorted( list(input()), reverse=True )

if s == t:
    print("No")
else:
    str_list = ["".join(s), "".join(t)]

    sorted_str_list = sorted(str_list)

    if str_list[0] == sorted_str_list[0]:
        print("Yes")
    else:
        print("No")
        

Measured memory_bytes: 2940
/**
*    created: 21.06.2020 23:49:31
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> c[n+1];
    rep(i,m) {
        int p, y;
        cin >> p >> y;
        c[p].push_back(make_pair(y,i+1));
    }
    rep2(i,1,n+1) sort(all(c[i]));
    vector<string> num(m+1);
    rep2(i,1,n+1) {
        rep(j,c[i].size()) {
            string s = to_string(1000000000000 + 1000000 * i + j+1);
            num[c[i][j].second] = s.substr(1,12);
        }
    }
    rep2(i,1,m+1) {
        cout << num[i] << endl;;
    }
    return 0;
}

Measured memory_bytes: 14888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 1009;
int N, K;
int p[MAX_N];

void solve()
{
	int ans = 0;
	sort(p,p+N);
	for(int i=0;i<K;++i) ans+=p[i];
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> K;
	for(int i=0;i<N;++i) cin >> p[i];
	solve();
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
// cout << "\t" << endl;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a;
  int zenbu = 0;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
    zenbu += tmp;
  }

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int count = 0;
  for (int i = 0; i < n; i++) {
    if (a.at(i) >= zenbu * (1.0 / (4.0 * m))) {
      count++;
      if (count == m) break;
    } else
      break;
  }
  if (count == m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 1001

int main(){
  
  int i,j,n,k;
  int x,y;
  char s[N],t[N];
  int l[N][N];

  scanf("%d",&n);

  for(k=0;k<n;k++){

    scanf("%s %s",s+1,t+1);
    x=strlen(s+1);
    y=strlen(t+1);

    for(i=1;i<=x;i++){
      for(j=0;j<=y;j++){
	l[i][j]=0;
      }
    }

    for(i=1;i<=x;i++){
      for(j=1;j<=y;j++){

	if(s[i]==t[j]){
	  l[i][j]=l[i-1][j-1]+1;
	}else if(l[i-1][j]>=l[i][j-1]){
	  l[i][j]=l[i-1][j];
	}else{
	  l[i][j]=l[i][j-1];
	}
      }
    }

    printf("%d\n",l[i-1][j-1]);
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  while(true){
    int n;
    cin >> n;
    if(n==0)break;
    bool flag = false;
    int cnt = 0;
    REP(i,n){
      int a;
      cin >> a;
      if(a>=2)flag = true;
      if(a>=1)++cnt;
    }
    if(flag)cout << (cnt+1) << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
string s;
ll N;
bool ok(ll x){
	ll I=0;
	ll OI=0;
	ll JOI=0;
	ll cnt=N-1;
	while(I+OI+JOI<x){
		if(cnt<0) return 0;
		if(s[cnt]=='I') I++;
		else if(s[cnt]=='O'){
			if(I>0){
				I--;
				OI++;
			}
		}
		else{
			if(OI>0){
				OI--;
				JOI++;
			}
		}
		cnt--;
	}
	rrep(i,cnt+1){
		if(s[i]=='I'||s[i]=='J'){
			if(OI>0){
				OI--;
				JOI++;
			}
		}
		else{
			if(I>0){
				I--;
				OI++;
			}
		}
	}
	return JOI>=x;
}


int main()
{
	cin>>N;
	cin>>s;
	ll lb=0;
	ll ub=N/3+1;
	while(ub-lb>1){
		ll mid=(ub+lb)/2;
		if(ok(mid)) lb=mid;
		else ub=mid;
	}
	cout<<lb<<endl;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
const int INF = 1e9;

bool vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
  }
  else { // 発見できなかったとき
    return false;
  }
}

int main() {
  int n;
  cin>>n;
  vector<int> A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  int m;
  cin>>m;
  int B[m];
  for(int i=0;i<m;i++){
    cin>>B[i];
  }
  for(int i=0;i<m;i++){
    if(A[B[i]-1]==2019||vector_finder(A,A[B[i]-1]+1)){

    }
    else{
      A[B[i]-1]++;
    }
  }
  for(int i=0;i<n;i++){
    cout<<A[i]<<endl;
  }
}


Measured memory_bytes: 3116
while line = gets
  input = line.chomp.split(',').map(&:to_i)

  l = input[0..9]
  v1, v2 = input[10..11]

  ratio = Rational(v1, v1 + v2)
  cumulative_sum = l.inject([]) do |memo, num|
    memo << (memo.last || 0) + num
    memo
  end

  intersect_point = cumulative_sum[-1] * ratio
  puts cumulative_sum.index { |num| num >= intersect_point } + 1
end

Measured memory_bytes: 8588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 100005
#define INF 9223372036854775807LL
#define MOD 1000000007
#define print(cs) printf("Case %lld: ",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b){return ((a*b)/__gcd(a,b));}
ll dp[13][13*MAX+5];
ll cost[15][15];
ll fn(ll idx,ll sum,ll arr[],ll n,ll m,ll x)
{
    if(idx==n)
    {
        bool ok=true;
        for(ll i=0;i<m;i++)
        {
            if(arr[i]<x)
            {
                ok=false;
                break;
            }
        }
        return (ok==true?sum:INF);
    }
    if(dp[idx][sum]!=-1)return dp[idx][sum];
    ll ret1=fn(idx+1,sum,arr,n,m,x);
    ll ret2;
    ll brr[m];
    for(ll i=0;i<m;i++)brr[i]=arr[i]+cost[idx][i+1];
    ret2=fn(idx+1,sum+cost[idx][0],brr,n,m,x);
    return dp[idx][sum]=min(ret1,ret2);
}
int main()
{
    ms(dp,-1);
    ll i,j,k,l,n,m,r,x;
    in(n);in(m);in(x);
    ll arr[n];
    for(i=0;i<n;i++)
    {
        arr[i]=0;
        in(cost[i][0]);
        for(j=1;j<=m;j++)in(cost[i][j]);
    }
    ll ans=fn(0,0,arr,n,m,x);
    if(ans==INF)ans=-1;
    cout<<ans<<'\n';
}


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

typedef long long ll;

const int maxn = 1e5 + 5;
const int inf = 1e9;

int n, m, cnt;
int tail[maxn], l[maxn], r[maxn], pa[maxn], val[maxn];
struct edge
{
    int v, next;
}e[maxn << 1];

void ins(int u, int v)
{
    e[++cnt] = (edge){v, tail[u]};
    tail[u] = cnt;
}

void dfs(int u)
{
    if(val[u] != -1)
	l[u] = r[u] = val[u];
    for(int i = tail[u]; i; i = e[i].next)
	if(e[i].v != pa[u])
	{
	    int v = e[i].v, s, t;
	    pa[v] = u;
	    dfs(v);
	    s = l[v] - 1, t = r[v] + 1;
	    if(l[v] == -inf)
		continue;
	    if(l[u] != -inf && (s & 1) != (l[u] & 1))
	    {
		puts("No");
		exit(0);
	    }
	    l[u] = max(l[u], s);
	    r[u] = min(r[u], t);
	    if(l[u] > r[u])
	    {
		puts("No");
		exit(0);
	    }	
	}
}

void solve(int u, int x)
{
    val[u] = x;
    for(int i = tail[u]; i; i = e[i].next)
	if(e[i].v != pa[u])
	{
	    if(x + 1 >= l[e[i].v] && x + 1 <= r[e[i].v])
		solve(e[i].v, x + 1);
	    else
		solve(e[i].v, x - 1);
	}
}

int main()
{
    int u, v, x;
    scanf("%d", &n);
    for(int i = 1; i < n; i++)
    {
	scanf("%d%d", &u, &v);
	ins(u, v);
	ins(v, u);
    }
    for(int i = 1; i <= n; i++)
    {
	val[i] = -1;
	l[i] = -inf;
	r[i] = inf;
    }
    scanf("%d", &m);
    for(int i = 1; i <= m; i++)
    {
	scanf("%d%d", &v, &x);
	val[v] = x;
    }
    dfs(1);
    puts("Yes");
    solve(1, l[1]);
    for(int i = 1; i <= n; i++)
	printf("%d\n", val[i]);
    return 0;
}


Measured memory_bytes: 9088
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//関係性は隣接行列で記録
//過半数：N/2.0で判定
//ある量からある量を引く系の問題：端から定義してやる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll R; cin >> R;
	cout << setprecision(20) << 2 * PI * R << endl;
}
	

Measured memory_bytes: 11020
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXN=1000;
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
struct QUEUE{
	int x,y,dep;
	QUEUE(){}
	QUEUE(int _x,int _y,int _dep){x=_x;y=_y;dep=_dep;}
};
int r,c,n;
int goal[10][2];
bool vis[MAXN+5][MAXN+5];
char maz[MAXN+5][MAXN+5];
int BFS(int *beg,int cnt){
	memset(vis,false,sizeof vis);
	queue<QUEUE> que;
	que.push(QUEUE(beg[0],beg[1],0));
	while(!que.empty())
	{
		QUEUE pre=que.front();que.pop();
		for(int i=0;i<4;i++)
		{
			int X=pre.x+dir[i][0],Y=pre.y+dir[i][1],depth=pre.dep+1;
			if(X<1 || X>r || Y<1 || Y>c || maz[X][Y]=='X' || vis[X][Y]) continue;
			vis[X][Y]=true;
			if(X==goal[cnt][0] && Y==goal[cnt][1])
				return depth;
			que.push(QUEUE(X,Y,depth));
		}
	}
	return -1;
}
int main(){
	scanf("%d%d%d",&r,&c,&n);
	for(int i=1;i<=r;i++)
	{
		scanf("%s",maz[i]+1);
		for(int j=1;j<=c;j++)
		{
			if('1'<=maz[i][j] && maz[i][j]<='9')
				goal[maz[i][j]-'0'][0]=i,
				goal[maz[i][j]-'0'][1]=j,
				maz[i][j]='.';
			if(maz[i][j]=='S')
				goal[0][0]=i,
				goal[0][1]=j,
				maz[i][j]='.';
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans+=BFS(goal[i-1],i);
	printf("%d\n",ans);
	return 0;
}//


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

int main(){
  ll n, ans = 1;
  ll const max = 1e18;
  cin >> n;
  ll arr[n];
  rep(i, n){
    cin >> arr[i];
    if(arr[i] == 0){
      cout << 0 << endl;
      return(0);
    }
  }
  rep(i, n){
    if(arr[i] >max/ans){
      cout << -1 << endl;
      return(0);
    }
    ans *= arr[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4412
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N, M = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

D = np.full((N, N), IINF)
for a, b, c in ABC:
    D[a - 1][b - 1] = c
    D[b - 1][a - 1] = c

# warshall floyd
for via in range(N):
    D = np.minimum(D, sum(np.meshgrid(D[via], D[via])))

ans = 0
for a, b, c in ABC:
    if D[a - 1][b - 1] < c:
        ans += 1
print(ans)


Measured memory_bytes: 21304
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr ll mod998=998244353;

int N,c;
string X;

ll pw(ll x,int y,ll m){
	ll a=1;
	if(!m)return 0;
	while(y){
		if(y&1)a=a*x%m;
		x=x*x%m;
		y/=2;
	}
	return a;
}

int f(int x,int cnt){
	if(x){
		int k=0;
		for(int i=0;i<20;i++){
			k+=1&(x>>i);
		}
		return f(x%k,cnt+1);
	}
	else return cnt;
}

int main(){
	cin>>N>>X;
	for(int i=0;i<N;i++){
		c+=X[i]-'0';
	}
	ll a,b;
	a=b=0;
	for(int i=0;i<N;i++){
		a+=pw(2,N-i-1,c+1)*(X[i]-'0');
		b+=pw(2,N-i-1,c-1)*(X[i]-'0');
		a%=c+1;
		b%=max(c-1,1);
	}
	for(int i=0;i<N;i++){
		if(X[i]=='1'){
			if(c==1)cout<<0<<endl;
			else cout<<f((b+c-1-pw(2,N-i-1,c-1))%(c-1),1)<<endl;
		}
		else{
			cout<<f((a+c+1+pw(2,N-i-1,c+1))%(c+1),1)<<endl;
		}
	}
}


Measured memory_bytes: 3752
/* Hello darkness my old friend, I've come to visit you again! */

#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1000000005
#define INF 1000000000000000005
#define io ios_base::sync_with_stdio(0);
#define ff first
#define ss second
using namespace std;

int cnt[26];
int main()
{
    io;
    cin.tie(0);
    cout.tie(0);
    int n,i,j,k,kk;
    string s;
    cin>>s>>k;
    n=s.length();
    set <string> st;
    string S="abcdefghijklmnopqrstuvwxyz";
    FOR(i,0,n)
    cnt[s[i]-'a']++;
    FOR(kk,0,26)
    {
        if(st.size()>=k)
            break;
        if(!cnt[S[kk]-'a'])
            continue;
        FOR(i,0,n)
        {
            if(s[i]!=S[kk])
                continue;
            int c=k;
            string str="";
            FOR(j,i,n)
            {
                if(!c)
                    break;
                c--;
                str+=s[j];
                st.insert(str);
            }
        }
    }
    //cout<<st.size();
   // sort(v.begin(),v.end());
    for(set <string> :: iterator it=st.begin();it!=st.end();it++)
    {
        //cout<<*it<<" ";
        if(k==1)
        {
            cout<<*it;
            return 0;
        }
        k--;
    }
    return 0;
}

/* This is the end, beautiful friend! */


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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define b_e(a) a.begin(),a.end() //sort(b_e(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define p_b push_back
#define SZ(x) ((ll)(x).size()) //size()がunsignedなのでエラー避けに
#define endk '\n'


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //


// --------- library end - //



int main(){

  ll N, Q;
  cin >> N >> Q;

  fenwick_tree<ll> fw(N);
  rep(i, N){
    fw.add(i, il());
  }

  rep(i, Q){
    ll t, u, v;
    cin >> t >> u >> v;

    if (!t){
      fw.add(u, v);
    }
    else{
      cout << fw.sum(u, v) << endk;
    }
  }



}



Measured memory_bytes: 8216
#include <iostream>
#include <vector>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main() {
	uint N, M;
	cin >> N >> M;
	
	vector<uint> A(N);
	for(uint i=0; i<N; i++) {
		cin >> A[i];
		A[i] >>= 1;
	}
	
	uint t = 0;
	uint a = A[0];
	while(a % 2 == 0) {
		t++;
		a >>= 1;
	}
	
	ull lcmA = 1;
	M >>= t;
	
	for(uint i=0; i<N; i++) {
		if(A[i] % (1 << t) != 0) {
			cout << 0;
			return 0;
		}
		
		A[i] >>= t;
		
		if(A[i] % 2 == 0) {
			cout << 0;
			return 0;
		}	
		
		lcmA = boost::math::lcm(lcmA, (ull)A[i]);
		
		if(lcmA > M) {
			cout << 0;
			return 0;
		}
	}
	
	ull ans = (M / lcmA + 1) / 2;
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int n = 100000;
    bool prime[n+1];
    int c[n+1];

    for (int i = 0; i <= n; i++) {
        prime[i] = true;
    }
    for (int i = 2; i <= n; i++) {
        if (prime[i]) {
            for (int j = i + i; j <= n; j += i) {
                prime[j] = false;
            }
        }
    }

    for (int i = 3; i <= n; i += 2) {
        if (prime[i] && prime[(i+1)/2]) {
            c[i]++;
        }
    }
    for (int i = 3; i <= n; i++) {
        c[i] += c[i-1];
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        scanf("%d %d", &l, &r);
        printf("%d\n", c[r] - c[l-1]);
    }

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int n;
  cin>> n;
  veci v(n);
  rep(i,n)cin>>v[i];
  sort(v.begin(),v.end());
  cout<<v[n/2]-v[n/2-1];
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
char c;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> c;
  printf("%c\n", (c + 1));
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 555555
#define mod 1000000007
int n,f[N],g[N],g2[N],d[N],s[N],lb[N],rb[N],tr[N],f2[N];
bool cmp(int a,int b){return s[a]==s[b]?d[a]<d[b]:s[a]<s[b];}
bool cmp2(int a,int b){return d[a]<d[b];}
void ad(int x,int s){for(int i=x;i<=n+1;i+=i&-i)tr[i]=(tr[i]+s)%mod;}
int qu(int x){int tp=0;for(int i=x;i;i-=i&-i)tp=(tp+tr[i])%mod;return tp;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&d[i],&s[i]),f[i]=f2[i]=i;
	sort(f+1,f+n+1,cmp);sort(f2+1,f2+n+1,cmp2);
	for(int i=1;i<=n;i++)g2[f2[i]]=i;
	for(int i=1;i<=n;i++)g[g2[f[i]]]=i;
	int mx=0;
	for(int i=1;i<=n;i++)
	mx=max(g[i],mx),rb[i]=mx;
	int mn=1e9;
	for(int i=n;i>=1;i--)
	mn=min(mn,g[i]),lb[i]=mn;
	ad(1,1);
	for(int i=1;i<=n;i++)
	ad(rb[i]+1,(qu(n+1)-qu(lb[i]-1)+mod)%mod);
	printf("%d\n",(qu(n+1)-qu(n)+mod)%mod);
}

Measured memory_bytes: 17408
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<vector>
#include<utility>
#define INF 0x3f3f3f3f3f3f3f3f
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'

using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	int k;cin >> k;
	ll ans = 0;
	for (int i = 1;i <= k;++i) {
		for (int j = 1;j <= k;++j) {
			for (int u = 1;u <= k;++u) {
				ans += gcd(i, gcd(j, u));
			}
		}
	}
	printf("%lld", ans);
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;

int X[MAX];
int A[MAX];

LL RES[MAX];

VI go(VI& p1, VI& p2)
{
	VI res(SZ(p1));
	FOR (i, 0, SZ(p1))
	{
		res[i] = p2[p1[i]];
	}

	return res;
}

VI go(VI& p, LL k)
{
	VI res;
	FOR (i, 0, SZ(p))
	{
		res.PB(i);
	}

	while(k)
	{
		if (k & 1) res = go(res, p);
		p = go(p, p);
		k /= 2;
	}

	return res;
}

int main()
{
	//freopen("in.txt","r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);
	FOR (i, 0, n)
	{
		scanf("%d", &X[i]);
	}

	int m;
	LL k;
	scanf("%d%lld", &m, &k);
	FOR (i, 0, m)
	{
		scanf("%d", &A[i]);
	}

	VI p(n - 1);
	FOR (i, 0, n-1)
	{
		p[i] = i;
	}

	FOR (i, 0, m)
	{
		swap(p[A[i] - 1], p[A[i] - 2]);
	}

	p = go(p, k);

	RES[0] = X[0];
	FOR (i, 0, SZ(p))
	{
		RES[i+1] = RES[i] + X[p[i]+1] - X[p[i]];
	}

	FOR (i, 0, n)
	{
		printf("%lld\n", RES[i]);
	}



}


Measured memory_bytes: 3936
program picking_goods
  implicit none
  integer :: n, m, k, i, j, l
  integer(8) :: v
  integer(8), allocatable :: g(:, :), dp(:, :, :)
  read(*,*) n, m, k
  allocate(g(n, m), dp(0:n, 0:m, 3))
  g = 0
  do l = 1, k
    read(*,*) i, j, v
    g(i, j) = v
  end do
  dp = 0
  do i = 1, n
    do j = 1, m
      dp(i, j, 1) = max(maxval(dp(i - 1, j, :)) + g(i, j), dp(i, j - 1, 1))
      dp(i, j, 2) = max(dp(i, j - 1, 1) + g(i, j), dp(i, j - 1, 2))
      dp(i, j, 3) = max(dp(i, j - 1, 2) + g(i, j), dp(i, j - 1, 3))
    end do
  end do
  write(*,'(i0)') maxval(dp(n, m, :))
end program picking_goods

Measured memory_bytes: 284112
#include<iostream>
using namespace std;
int main(){
	int w,h;
	cin>>h>>w;
	int num;
	cin>>num;
	int field[100][100];
	int data[10000];
	for(int i=0;i<num;i++){
		cin>>data[i];
	}
	int k=0;
	for(int i=0;i<h;i++){
		if((i%2)==0){
			for(int j=0;j<w;j++){
				if(data[k]==0)k++;
				field[i][j]=k+1;
				data[k]--;
			}
		}
		if((i%2)==1){
			for(int j=w-1;j>=0;j--){
				if(data[k]==0)k++;
				field[i][j]=k+1;
				data[k]--;
			}
		}		
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout<<field[i][j]<<' ';
			
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
		int H = sc.nextInt(), W = sc.nextInt();
		int grid[][] = new int[H+2][W+2];
		for(int i = 1; i<=H; i++) {
			String s = sc.next();
			for(int j = 1; j<=W; j++) {
				if(s.charAt(j-1) == '#') grid[i][j] = -1;
				}
		}
		for(int i = 1; i<=H; i++) {
			for(int j = 1; j<=W; j++) {
				if(grid[i][j] == -1) continue;
				int count = 0;
				if(grid[i-1][j-1] == -1) count++;
				if(grid[i-1][j] == -1) count++;
				if(grid[i-1][j+1] == -1) count++;
				if(grid[i][j+1] == -1) count++;
				if(grid[i+1][j+1] == -1) count++;
				if(grid[i+1][j] == -1) count++;
				if(grid[i+1][j-1] == -1) count++;
				if(grid[i][j-1] == -1) count++;
				grid[i][j] = count;
			}
		}
		
		for(int i = 1; i<=H; i++) {
			for(int j = 1; j<=W; j++) {
				if(grid[i][j] == -1) System.out.print('#');
				else System.out.print(grid[i][j]);
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 22356
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const double INF = 1e9;

int N, L;
vector<int> v;

void input(string &str, char delim){
  stringstream ss(str);
  string tmp;
  bool f = true;
  while(getline(ss, tmp, delim)){
    if(f) { L = atoi(tmp.c_str()); f = false; }
    else v.push_back(atoi(tmp.c_str()));
  }
  N = v.size();
}

int main() {
  string s;
  while(getline(cin, s)){
    v = vector<int>();
    input(s, ' ');
    vector< vector<double> > dp((1 << N), vector<double>(N, INF));
    REP(i, N) dp[(1 << i)][i] = v[i];
    REP(bit, (1 << N)){
      REP(bef, N){
        if(dp[bit][bef] == INF) continue;
        //cout <<bitset<3>(bit).to_string() <<", " <<bef <<" = " <<dp[bit][bef] <<endl;
        REP(n, N){
          if(1 & (bit >> n)) continue;
          int nb = bit | (1 << n);
          double l = sqrt((v[bef] + v[n]) * (v[bef] + v[n]) - (v[bef] - v[n]) * (v[bef] - v[n]));
          if(nb == (1 << N) - 1) l += v[n];
          //cout <<"    " <<bitset<3>(nb).to_string() <<", " <<n <<" = min(" <<dp[nb][n] <<", " <<dp[bit][bef] <<" + " <<l <<")" <<endl;
          dp[nb][n] = min(dp[nb][n], dp[bit][bef] + l);
        }
      }
    }
    double len = INF;
    REP(i, N) len = min(len, dp[(1 << N) - 1][i]);
    cout <<(len <= L ? "OK" : "NA") <<endl;
  }
  return 0;
}

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

c = []
for _ in range(3):
    line = list(map(int, input().split()))
    c.append(line)

for a1 in range(max(c[0])+1):
    for a2 in range(max(c[1])+1):
        for a3 in range(max(c[2])+1):
            b1 = c[0][0] - a1
            b2 = c[1][1] - a2
            b3 = c[2][2] - a3
            if a1+b1!=c[0][0]:
                continue
            if a1+b2!=c[0][1]:
                continue
            if a1+b3!=c[0][2]:
                continue
            if a2+b1!=c[1][0]:
                continue
            if a2+b2!=c[1][1]:
                continue
            if a2+b3!=c[1][2]:
                continue
            if a3+b1!=c[2][0]:
                continue
            if a3+b2!=c[2][1]:
                continue
            if a3+b3!=c[2][2]:
                continue
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3064
/* Simplicity and Goodness */
 
#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;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


void solve()
{   
    int n, k;
    scn(n); scn(k);

    int a[n];

    rep(i, 0, n)
    scn(a[i]);

    sort(a, a+n);

    int total = accumulate(a, a+k, 0);

    prin(total);
}

int main()
{
    int t = 1;
    // scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

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

static const ll INF = 20000000000;



int main(){
    ll a,b,q;
    cin >> a>> b>> q;
    vector<ll> s(a+2), t(b+2);
    s[0]=-1*INF;
    t[0]=-1*INF;
    
    rep2(i,a) cin >> s[i];
    rep2(i,b) cin >> t[i];
    s[a+1]=INF;
    t[b+1]=INF;
    //２分対策でまず場所を考える
    rep2(i,q){
        ll res=INF;
        ll x;
        cin >> x;
        //sort(s.begin(),s.end());//sortしてないとupperboundは使えないこともある　　というか並ばせとけ
        //sort(t.begin(),t.end());

        ll shrine=upper_bound(s.begin(),s.end(),x)-s.begin();//upper_bound ２分探索ライブラリ　探索したいkeyより大きいイテレータを返す//イテレータとはポイントで、begin()は一番左のポインタのことなので要するに何-1番目の神社かを示している。
        ll temple=upper_bound(t.begin(),t.end(),x)-t.begin();

        res=min(res,min(abs(t[temple]-x),abs(s[shrine]-x))+abs(t[temple]-s[shrine]));//両方xより大きい方に行った。
        res=min(res,min(abs(t[temple-1]-x),abs(s[shrine]-x))+abs(t[temple-1]-s[shrine]));
        res=min(res,min(abs(t[temple]-x),abs(s[shrine-1]-x))+abs(t[temple]-s[shrine-1]));
        res=min(res,min(abs(t[temple-1]-x),abs(s[shrine-1]-x))+abs(t[temple-1]-s[shrine-1]));

        cout<<res<<endl;
    }
}

Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int a = sc.nextInt();
            if (a==0)break;
            for (int i = 0; i < a; i++) {
                int pm = sc.nextInt();
                int pe = sc.nextInt();
                int pj = sc.nextInt();

                if (pm == 100 || pe == 100 || pj == 100 || (pm + pe) / 2 >= 90 || (pm + pe + pj) / 3 >= 80) {
                    System.out.println("A");
                } else if ((pm + pe + pj) / 3 >= 70 || (pm + pe + pj) / 3 >= 50 && (pm >= 80 || pe >= 80)) {
                    System.out.println("B");
                } else {
                    System.out.println("C");
                }
            }
        }
    }
}

Measured memory_bytes: 28296
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    Q=int(input())
    S = tuple(tuple(map(int, input().split())) for i in range(Q)) #改行行列
    ca=Counter(A)
    tot=sum(A)
    for B,C in S:
        red=ca[B]
        ca[B]=0
        ca[C]+=red
        tot+=red*(C-B)
        print(tot)





if __name__ == "__main__":
    main()

Measured memory_bytes: 108784
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

a2 = (a+9)//10 * 10
b2 = (b+9)//10 * 10
c2 = (c+9)//10 * 10
d2 = (d+9)//10 * 10
e2 = (e+9)//10 * 10

sum = a2+b2+c2+d2+e2
ans = 1e18
ans = min(ans, sum-a2+a)
ans = min(ans, sum-b2+b)
ans = min(ans, sum-c2+c)
ans = min(ans, sum-d2+d)
ans = min(ans, sum-e2+e)

print(ans)

Measured memory_bytes: 9224