akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <map>
#include <cstdio>
#include <algorithm>

using namespace std;

void Get_Val(int &Ret)
{
	Ret = 0;
	char ch;
	while (ch = getchar(), ch > '9' || ch < '0')
		;
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
}

const int Max_N(100050);

struct edge
{
	edge(const int &_u = 0, const int &_v = 0) : u(_u), v(_v) {}
	int u, v;
};

inline bool operator<(const edge &a, const edge &b)
{
	return a.u == b.u ? a.v < b.v : a.u < b.u;
}

int N, Father[Max_N];
map<int, int> To[Max_N];
map<edge, int> C;
set<edge> S;

int Get_Father(const int &x)
{
	return Father[x] == x ? x : Father[x] = Get_Father(Father[x]);
}

inline void insert(int u, int v)
{
	if (u == v)
		return;
	++To[u][v];
	++To[v][u];
	if (u > v)
		swap(u, v);
	if ((++C[edge(u, v)]) == 2)
		S.insert(edge(u, v));
}

inline void erase(int u, int v)
{
	if (u == v)
		return;
	if ((--To[u][v]) == 0)
		To[u].erase(v);
	if ((--To[v][u]) == 0)
		To[v].erase(u);
	if (u > v)
		swap(u, v);
	if ((--C[edge(u, v)]) == 1)
		S.erase(edge(u, v));
}

void init()
{
	Get_Val(N);
	for (int i = 1;i <= N;++i)
		Father[i] = i;
	for (int i = 1, u, v;i != N;++i)
		Get_Val(u), Get_Val(v), insert(u, v);
	for (int i = 1, u, v;i != N;++i)
		Get_Val(u), Get_Val(v), insert(u, v);
}

void work()
{
	for (int CNT = 1, u, v, p, t;CNT <= N - 1;++CNT)
	{
		if (S.empty())
		{
			printf("NO");
			return;
		}
		u = S.begin() -> u, v = S.begin() -> v;
		if (To[u].size() < To[v].size())
			swap(u, v);
		while (To[v].size())
		{
			p = To[v].begin() -> first;
			t = To[v].begin() -> second;
			for (int i = 1;i <= t;++i)
			{
				erase(v, p);
				insert(u, p);
			}
		}
	}
	printf("YES");
}

int main()
{
	init();
	work();
	return 0;
}

Measured memory_bytes: 37504
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <set>
#define ll long long
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define sz(a) int((a).size())
#define shit while(t--)
#define fr for(int i=0;i<n;i++)
int maxo=1e9+7;
using namespace std;
int arr[95];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
int a,b,x=0;

cin>>a>>b;
for(int i=a;i<=b;i++){
int reversedInteger = 0, remainder, originalInteger,temp;
 
 
    originalInteger=i;
    temp=i;
    while( temp!=0 )
    {
        remainder = temp%10;
        reversedInteger = reversedInteger*10 + remainder;
        temp/= 10;
    }
    if (originalInteger == reversedInteger)
        x++;
}
cout<<x;
return 0;
}

Measured memory_bytes: 3660
use proconio::input;

fn main() {
    input! {
        n: usize,
    }

    let mut sum = 0;

    for i in 1..=n {
        if (i % 3 != 0) && (i % 5 != 0) {
            sum += i;
        }
    }

    println!("{}", sum);
}


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

int main(){
  long long int s[10000],t[500];
  
  int n,q,a,b=0,ans=0;
  bool c=true;
  cin>>n;
  for(int i=0;i<n;i++) cin>>s[i];
  cin>>q;
  for(int i=0;i<q;i++) cin>>t[i];
  sort(s,s+n);
  a=s[0];
  for(int i=0;i<n;i++){
    if(s[i]==a && i!=0) continue;
    else a=s[i];
    for(int j=0;j<q;j++){
      if(s[i]==t[j]){
	ans++;
	break;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;

// #define DEBUG

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, q;
    cin >> n >> q;
    
    ll x, s, t, ans;
    s = t = 0;
    ll a[n+1] = {};
    for (int i = 0; i < n; i++)
    {
        cin >> t;
        s += t;
        a[i+1] = s;
    }
    for (int i = 0; i < q; i++)
    {
        ans = 0;
        cin >> x;
        for (int j = 0; j < n; j++)
        {
            ans += distance(a + j + 1, upper_bound(a + j + 1, a + n + 1, x + a[j]));
        }
        cout << ans << endl;
    }
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3880
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

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

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/


int binary_search(int* p, int n, int key,int num)
{
    int low, high, middle;

    low = 0;
    high = n - 1;

    while (low <= high)
    {
        middle = (low + high) / 2;
        if (gcd(num,p[middle])==1)
            return middle;
        else 
            high = middle - 1;
    }
}

int main()
{
    int N, L, M, K;
    int S, W;
    int a[100000];

    scanf("%d%d", &S,&W);

    if (S <= W)
        printf("unsafe");
    else
        printf("safe");
}



Measured memory_bytes: 3824
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

int n,k;
int a;

int main()
{
	scanf("%d %d",&n,&k);
	int ans=0;
	for(register int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a>=k) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>


int main() {
	int n, m; std::cin >> n >> m;
	int s = 0;
	for (int i = 0; i < m; i++) {
		int a; std::cin >> a;
		s += a;
	}
	if (s > n) std::cout << -1 << std::endl;
	else std::cout << n - s << std::endl;
	return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int x;
    scanf("%d", &x);
    if (x < 600) {
        printf("8\n");
    }
    else if (x < 800) {
        printf("7\n");
    }
    else if (x < 1000) {
        printf("6\n");
    }
    else if (x < 1200) {
        printf("5\n");
    }
    else if (x < 1400) {
        printf("4\n");
    }
    else if (x < 1600) {
        printf("3\n");
    }
    else if (x < 1800) {
        printf("2\n");
    }
    else {
        printf("1\n");
    }
    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 1660
#include <stdio.h>


int main()
{
  
   long long int a,b,c,d,l,ans=0,minMultiple,n ;
   long long int n1,n2,n3,u,v,w,x,y,z;
   long long int gcd, lcm, remainder, numerator, denominator;
 
   
   scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
  n=b-a+1;
  u=a/c;
  if(a%c!=0)
  {
      u++;
  }
  v=b/c;
  n1=v-u+1;
  
  
   w=a/d;
  if(a%d!=0)
  {
      w++;
  }
  x=b/d;
  n2=x-w+1;
  
/*  minMultiple = (c>d) ? c : d;
    // Always true
    while(1)
    {
        if( minMultiple%c==0 && minMultiple%d==0 )
        {
            l=minMultiple;
            break;
        }
        ++minMultiple;
    }
  */
  if (c > d)
    {
        numerator = c;
        denominator = d;
    }
    else
    {
        numerator = d;
        denominator = c;
    }
    remainder = numerator % denominator;
    while (remainder != 0)
    {
        numerator   = denominator;
        denominator = remainder;
        remainder   = numerator % denominator;
    }
        gcd = denominator;
    lcm = c * d / gcd;
  l=lcm;
  
  y=a/l;
  if(a%l!=0)
  {
      y++;
  }
  z=b/l;
  n3=z-y+1;
  
  ans=n1+n2-n3 ;

  
  ans=n-ans;
  
   
   printf("%lld",ans);
   
    
    return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

# BIT木

# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

N, M, Q = mi()
bit = BIT(N)
lrpq = dp2(0, 3, M+Q)

for i in range(M):
    l, r = mi()
    lrpq[i][1] = l-1
    lrpq[i][2] = r-1

for i in range(M, M+Q):
    p, q = mi()
    lrpq[i][0] = i
    lrpq[i][1] = p-1
    lrpq[i][2] = q-1

lrpq = sorted(lrpq, key=lambda x:(x[2], x[0]))

ans = [0]*(Q)

for i in range(M+Q):
    if lrpq[i][0] == 0:
        #L[lrpq[i][1]] += 1
        bit.add(lrpq[i][1]+1, 1)
        #BIT_update(lrpq[i][1]+1, 1)
    else:
        bit.sum(lrpq[i][2])
        if lrpq[i][1] > 0:
            ans[lrpq[i][0]-M] = bit.sum(lrpq[i][2]+1) - bit.sum(lrpq[i][1])
        else:
            ans[lrpq[i][0]-M] = bit.sum(lrpq[i][2]+1)

for num in ans:
    print(num)

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.next();
		char[] words = s.toCharArray();
		for(int i = 0; i < s.length(); i += 2) {
			System.out.print(words[i]);
		}

	}

}

Measured memory_bytes: 31292
using System;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] a = sc.IntArray();
        long ans = long.MaxValue;
        for (int i = -100; i <=100 ; i++)
        {
            long sum = 0;
            foreach (int j in a)
            {
                sum += (j - i) * (j - i);
            }

            ans = Math.Min(ans, sum);
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;

int n;

void input() {
    cin >> n;
}

void solve() {
    array<double, 50005> tmp;
    array<double, 50005> x;
    iota(tmp.begin(), tmp.end(), 0);
    for(size_t i = 0; i < x.size(); i++) {
        x.at(i) = tmp.at(i) * 1.08;
        if(floor(x.at(i)) == n) {
            cout << tmp.at(i) << endl;
            return;
        }
    }
    cout << ":(" << endl;


}
int main() {
    input();
    solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll d[2555][8888];

void Main() {
  ll n,m,t;
  cin >> n >> m >> t;
  vector<P> v[n];
  rep(i,m) {
    ll x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    v[x].pb(P(y,z));
  }
  rep(i,n)rep(j,8888) d[i][j]=-MAXL;
  d[0][0]=0;
  rep(k,8887) {
    rep(x,n) {
      rep(j,v[x].size()) {
        ll y=v[x][j].F,c=v[x][j].S;
        d[y][k+1]=max(d[y][k+1],d[x][k]+c-t);
      }
    }
  }
  ll ans=-MAXL,k=0;
  rep(i,8888) {
    if(ans<d[n-1][i]) {
      ans=d[n-1][i];
      k=i;
    }
  }
  if(k>=8880-n) ans=-1;
  else ans=max(ans,0LL);
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 174592
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Wed Jan  9 09:19:53 2019
//
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)
	m := map[rune]int{}
	for _, c := range S {
		m[c] = 1
	}

	for _, alpha := range "abcdefghijklmnopqrstuvwxyz" {
		if _, ok := m[alpha]; !ok {
			fmt.Println(string(alpha))
			return
		}
	}
	fmt.Println("None")
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    unsigned long long int Q,H,S,D,N,ans = 0, x, y,z, w;
    scanf("%llu%llu%llu%llu", &Q, &H, &S, &D);
    scanf("%llu",&N);

    x=min(2llu*Q,H);
    y=min(2llu*x,S);
    z=min(2llu*y,D);
    ans=N/2llu*z+N%2*y;
    printf("%llu\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <numeric>
using namespace  std;
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define filla(a,k,n) memset(a,k,sizeof(a[0])*n)
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll dp[100005];
ll a[100005];
ll i,j;
ll pow1(ll a,ll b)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return pow1(a*a,b/2);
    else
        return a*pow1(a*a,b/2);
}
void solve(ll n)
{
    //cout<<n<<"\n";
    if(dp[n]!=-1)
        return;
    if(n==1)
    {
        dp[n]=0;
        return;
    }
    solve(n-1);
    if(n==2)
    {
        dp[n]=abs(a[n-1]-a[n]);
        return;
    }
    solve(n-2);
    dp[n]=min(dp[n-2]+abs(a[n-2]-a[n]),dp[n-1]+abs(a[n-1]-a[n]));
    return;
}
int main()
{
    ll n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    fillv(dp,-1);
    solve(n);
    cout<<dp[n];


}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;

int main(){
  int N,W; cin>>N>>W;
  vector<ll> w(N),v(N); rep(i,N)cin>>w.at(i)>>v.at(i);
  //dpの定義
  //N*Wで100000
  // dp[i][h] i in [0,N]
  vector<vector<ll>> dp(N+1,vector<ll> (W+1,0));
  rep1(i,N){
    rep1(h,W){
      //i番目の品物を使うパターン
      if(h-w.at(i-1)<0)dp.at(i).at(h)=dp.at(i-1).at(h);
      else dp.at(i).at(h) = max(dp.at(i-1).at(h),dp.at(i-1).at(h-w.at(i-1))+v.at(i-1));
    }
  }
  ll res = 0;
  rep(i,W+1) res = max(res,dp.at(N).at(i));
  cout<<res<<endl;
}


Measured memory_bytes: 80256
#include <cstdio>
#include <set>
using namespace std;

int main(void)
{
    int N,x;
    scanf("%d",&N);
    set<int> s;
    while(N--)
    {
        scanf("%d",&x);
        if(s.count(x)==0)
            s.insert(x);
        else
            s.erase(x);
    }
    printf("%d\n",s.size());
    return 0;
}


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

namespace ABC165
{
    class B
    {
        static long N;
        static long M;
        static long Q;
        static long[][] abcd;
        static long ans;
        static void Main(string[] args)
        {
            //var X = long.Parse(Console.ReadLine());
            var NMQ = Console.ReadLine().Split().Select(long.Parse).ToArray();
            N = NMQ[0]; M = NMQ[1]; Q = NMQ[2];
            abcd = Enumerable.Repeat(0, (int)Q).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();

            var list = new List<long>();
            DFS(1, list, N);

            Console.WriteLine(ans);
        }

        static void DFS(int min, List<long> list, long len)
        {
            if (len == 0)
            {
                long sum = 0;
                for (int q = 0; q < Q; q++)
                {
                    if (list[(int)abcd[q][1] - 1] - list[(int)abcd[q][0] - 1] == abcd[q][2]) sum += abcd[q][3];
                }
                ans = Math.Max(ans, sum);
                return;
            }

            for (int i = min; i <= M; i++)
            {
                list.Add(i);
                DFS(i, list, len - 1);
                list.RemoveAt(list.Count - 1);
            }
        }
    }
}


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

int main() {
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;
  int cnt = 0;
  int b_cnt = 0;
  for (int i = 0; i < n; i++) {
    bool pass = false;
    if (s.at(i) == 'a' && cnt < a + b) {
      pass = true;
    }
    else if (s.at(i) == 'b' && cnt < a + b && b_cnt < b) {
      pass = true;
      b_cnt++;
    }
    if (pass) {
      cout << "Yes" << endl;
      cnt++;
    }
    else {
      cout << "No" << endl;
    }
  }
  return 0;
}




Measured memory_bytes: 3696
#include <iostream>
#include <unordered_map>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define rep(i,min,max) for(int i = min; i < max; i++)
#define rrep(i,max,min) for(int i=max; min <= i; i--)

#define inf 1e+6

int N, H, W;

int main(){
  int ans = 0;
  cin >> N >> H >> W;
  int A[N], B[N];
  rep(i, 0, N) cin >> A[i] >> B[i];
  rep(i, 0, N){
    if(H <= A[i] && W <= B[i]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		int d=0;
		for(int i = 0;i<n;i++) {
			if(a[i]!=i+1){
				d++;
			}
		}
		Console.WriteLine("{0}",d<=2?"YES":"NO");
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    const lint MOD = 1e9 + 7;
    lint N;
    cin >> N;
    vec<string> pattern(2);
    range(i, 0, 2) {
        cin >> pattern.at(i);
    }
    if (N == 1) {
        cout << 3 << "\n";
        return 0;
    }
    else if (N == 2) {
        cout << 6 << "\n";
        return 0;
    }
    lint start, num_patterns;
    bool vertical;
    if (pattern.at(0).at(0) == pattern.at(0).at(1)) {
        start = 2;
        num_patterns = 6;
        vertical = false;
    } else {
        start = 1;
        num_patterns = 3;
        vertical = true;
    }
    lint cur_col = start;
    while (cur_col < N) {
        if (cur_col == N - 1 || pattern.at(0).at(cur_col) != pattern.at(0).at(cur_col + 1)) {
            num_patterns *= (vertical ? 2 : 1);
            num_patterns %= MOD;
            vertical = true;
            cur_col += 1;
        } else {
            num_patterns *= (vertical ? 2 : 3);
            num_patterns %= MOD;
            vertical = false;
            cur_col += 2;
        }
    }
    cout << num_patterns << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a=0,b=0,c=0,d=0,e=0,t=0;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a<0){
		t=-a*c+d+e*b;
	}
	else{
		t=(b-a)*e;
	}
	printf("%d\n",t);
	return 0;
}

Measured memory_bytes: 1824
str_lis = input().split()
A, B, K = [int(x) for x in str_lis]
N = min(A, B)
num_lis = [n for n in range(1, N + 1) if A % n == 0 and B % n == 0]
lis = num_lis[::-1]
print(lis[K - 1])

Measured memory_bytes: 3060
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#累積和
#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が最も高効率

def input(): return sys.stdin.readline()[:-1]
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())
    X,N = map(int, input().split())
    if N==0:
        _=input()
        print(X)
        return 
    A = list(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    
    A.sort()
    a=A

    i=bisect_left(A,X)
    
    if i==len(A):
        print(X)
        return 
    if A[i]!=X:
        print(X)
        return
    
    j=i-1
    cur=X
    amin=min(A)-1
    while j>=0:
        if abs(a[j]-cur)<2:
            cur=a[j]
            j-=1
            continue
        else:
            amin=cur-1
            break
    j=i+1
    amax=max(A)+1
    cur=X
    while j<=len(A)-1:

        if abs(a[j]-cur)<2:
            cur=a[j]
            j+=1
            continue
        else:
            amax=cur+1
            break
    
    if abs(amin-X)<=abs(amax-X):
        print(amin)
    else:
        print(amax)
    
if __name__ == "__main__":
    main()

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

int n;
const int MAXN = 16;
const int MAXP = 1<<MAXN;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
ll mem[MAXP];
ll vbm[MAXP];
ll v[MAXN][MAXN];

ll dp(int bm) {
  ll & ans = mem[bm];
  if (bm==0) return 0;
  if (ans!=-INF) return ans;
  //cerr << bm <<endl;
  for(int s = bm; s;s=(s-1)&bm) {
    ans = max(ans, vbm[s]+dp(bm^s));
  }
  return ans;
}

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n;
  memset(mem, -1,sizeof mem);
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin >> v[i][j];
  for(int b=0;b<(1<<n);b++){
    mem[b] = -INF;
    for(int i=0;i<n;i++) {
      for(int j=0;j<i;j++) {
        if (b>>i&1 && b>>j&1) vbm[b]+=v[i][j];
      }
    }
  }
  cout << dp((1<<n)-1) <<endl;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    string s; 
    int k;
    cin >> s >> k;
   for(int i = 0; i < min<int>(s.size(),k); i++){
       if(s[i] > '1')
       {
           cout << s[i] << endl;
           return 0;
       }
   }
   cout << 1 << endl;
}

Measured memory_bytes: 256
#include<cstdio>

//using namespace std;

#define debug
#ifdef debug

#else

#endif 



int main (){
	int a,b,c,d;
	a=getchar()-'0';
	b=getchar()-'0';
	c=getchar()-'0';
	d=getchar()-'0';
//	printf("%d",a);
	//scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+b+c+d>7){
		if(a+b+c-d==7){printf("%d+%d+%d-%d=7\n",a,b,c,d);}else
		if(a+b-c+d==7){printf("%d+%d-%d+%d=7\n",a,b,c,d);}else
			if(a+b-c-d==7){printf("%d+%d-%d-%d=7\n",a,b,c,d);}else
				if(a-b+c+d==7){printf("%d-%d+%d+%d=7\n",a,b,c,d);}else
					if(a-b+c-d==7){printf("%d-%d+%d-%d=7\n",a,b,c,d);}else
						if(a-b-c+d==7){printf("%d-%d-%d+%d=7\n",a,b,c,d);}else
							if(a-b-c-d==7){printf("%d-%d-%d-%d=7\n",a,b,c,d);}	
	}else printf("%d+%d+%d+%d=7\n",a,b,c,d);
	return 0;
}

Measured memory_bytes: 128
N = gets.to_i
A = gets.split(" ").map(&:to_i)
change_times = 0
def bubleSort(a, n, change_times)
  flag = 1
  while flag == 1
    flag = 0
    for j in (1..n-1).to_a.reverse
      if a[j] < a[j-1]
        karinotoko = a[j]
        a[j] = a[j-1]
        a[j-1] = karinotoko
        flag = 1
        change_times += 1
      end
    end
  end
  return [change_times, a]
end

change_times, sortedA = bubleSort(A, N, change_times)
puts sortedA.join(" ")
puts change_times


Measured memory_bytes: 6988
program test
implicit none
integer :: i,n,m,x,a(100),aa(100)=0, cost

read(*,*)  n,m,x
read(*,*)  (a(i),i=1,m)

do i = 1, m
 aa(a(i)) = 1
enddo

cost = min(sum(aa(:x-1)),sum(aa(x+1:)))

write(*,*) cost

end program

Measured memory_bytes: 768
d,g=map(int,input().split())
p=[0 for _ in range(d)]
c=[0 for _ in range(d)]
ans = 100**10

for i in range(d):#値を取得！
	p[i],c[i]=map(int,input().split())

for i in range(2**d):
	score = 0
	count = 0
	horyu = 0
	for j in range(d):
		if ((i >> j) & 1):
			score += (j+1)*p[j]*100 + c[j]
			count += p[j]
		else:
			horyu = j #あとまわし(最高点数の1種類)
	for i in range(p[horyu]):
		if score >= g and count < ans:
			ans = count
		score += (horyu + 1) * 100
		count += 1

print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
import java.util.jar.JarOutputStream;

public class Main {

    public static int lower_bound(long[] arr,long target){
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int W= Reader.nextInt();
        int[] w=new int[n];
        int[] cost=new int[n];
        for(int i=0;i<n;i++){
            int[] ar = Reader.nextIntArray(2);
            w[i] = ar[0];
            cost[i] = ar[1];
        }
        long[][] dp=new long[n+1][W+1];
        int c=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=W;j++){
                if(j<w[i-1]){
                    dp[i][j] = dp[i-1][j];
                }
                else{
                    dp[i][j] = Math.max(dp[i-1][j],dp[i-1][j-w[i-1]]+cost[i-1]);
                    c += 1;
                }
            }
        }
        //System.out.println(c);
        System.out.println(dp[n][W]);

    }

}






class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( nextLine() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( nextLine() );
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat( nextLine() );
    }
    static int[] nextIntArray(int length) throws IOException {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    }
    static long[] nextLongArray(int length) throws IOException {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    }

}



Measured memory_bytes: 138348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
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;
}
ll n,m,x,y;
vl g[110000];
ll dp1[110000],dp2[110000];
ll ans[110000];
void dfs1(ll x,ll last=-1){
    ll res=1;
    for(auto next:g[x]){
        if(next==last)continue;
        dfs1(next,x);
        res*=dp1[next];
        res%=m;
    }
    dp1[x]=res+1;
    dp1[x]%=m;
}
void dfs2(ll x,ll last=-1){
    if(last==-1)dp2[x]=1;
    vl lcnt(sz(g[x]),1);
    vl rcnt(sz(g[x]),1);
    for(int i=0;i<sz(g[x]);i++){
        ll next=g[x][i];
        if(i>=1)lcnt[i]=lcnt[i-1];
        if(next==last)continue;
        else{
            lcnt[i]*=dp1[next];
            lcnt[i]%=m;
        }
    }
    for(int i=sz(g[x])-1;i>=0;i--){
        ll next=g[x][i];
        if(i<sz(g[x])-1)rcnt[i]=rcnt[i+1];
        if(next==last)continue;
        else{
            rcnt[i]*=dp1[next];
            rcnt[i]%=m;
        }
    }
    for(int i=0;i<sz(g[x]);i++){
        ll next=g[x][i];
        if(next==last)continue;
        ll res=1;
        if(i!=0)res*=lcnt[i-1],res%=m;
        if(i!=sz(g[x])-1)res*=rcnt[i+1],res%=m;
        dp2[next]=(res*dp2[x]+1)%m;
        dfs2(next,x);
    }
}
void dfs3(ll x,ll last=-1){
    ans[x]=dp2[x];
    for(auto next:g[x]){
        if(last==next)continue;
        ans[x]*=dp1[next];
        ans[x]%=m;
        dfs3(next,x);
    }
}
int main(){
    cin>>n>>m;
    rep(i,n-1){
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs1(1);
    dfs2(1);
    dfs3(1);
    rrep(i,n)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 21960
N, M = map(int, input().split())
num = [-1] * N

ok = True
for _ in range(M):
    s, c = map(int, input().split())
    if num[s - 1] == -1 or num[s - 1] == c:
        num[s - 1] = c
    else:
        ok = False

if not ok:
    print(-1)
elif N >= 2 and num[0] == 0:
    print(-1)
elif N == 1:
    print(max(num[0], 0))
else:
    if num[0] == -1:
        num[0] = 1
    for i, n in enumerate(num):
        if n == -1:
            num[i] = 0

    ans = int("".join(map(str, num)))
    print(ans)



Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

int64_t f(const vector<int64_t>& a, int64_t m) {
    int64_t n = a.size();
    vector<int64_t> b(n);
    int64_t l = 0;
    for (auto i : irange(0L, n)) {
        b[i] = a[i] % m;
        l += b[i];
    }
    l /= m;

    sort(b.rbegin(), b.rend());

    int64_t c = 0;
    for (auto i : irange(0L, l)) {
        c += m - b[i];
    }
    for (auto i : irange(l, n)) {
        c += b[i];
    }

    return c / 2;
}

main() {
    int64_t n, k;
    cin >> n >> k;

    vector<int64_t> a(n);
    int64_t s = 0;
    for (auto&& aa : a) {
        cin >> aa;
        s += aa;
    }

    int64_t ans = -1;
    for (int64_t m = 1; m * m <= s; ++m) {
        if (s % m > 0) {
            continue;
        }

        auto c = f(a, m);
        if (c <= k) {
            ans = max(ans, m);
        }

        auto m2 = s / m;
        auto c2 = f(a, m2);
        if (c2 <= k) {
            ans = max(ans, m2);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	double x;
	string u[n];
	double sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> x >> u[i];
		if (u[i] =="JPY") {
			sum = sum + x;
		}
		else {
			sum = sum + x * 380000;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>
#include<sstream>
using namespace std;
#define all(a) a.begin(),a.end()


int main()
{
	string s;
	while(getline(cin,s))
	{
		if(s=="0")break;
		stringstream ss(s);
		int sum=0,c=0;
		int x;
		while(ss>>x)
		{
			sum+=min(10,x);
			if(x==1)c++;
		}
		while(sum+10<=21&&c)
		{
			c--;
			sum+=10;
		}
		if(sum>21)sum=0;
		
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 3052
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cctype>
#include <map>
#include <cstring>
#include <typeinfo>
#include <utility>
#define REP(i,n) for(int i = 0;i < n ;i++)
#define FOR(i,m,n) for(int i= m ;i<n;i++)
using namespace std;

int main(void){
  int N,L;
  cin >> N >> L;
  string str[N],ans,tmp;
  int i,j;
  for(i=0;i<N;i++){
    cin >> str[i];
  }
  for(i=0;i<N-1;i++){
    for(j=N-1;j>i;j--){
      if(str[j-1]>str[j]){
        tmp=str[j-1];
        str[j-1]=str[j];
        str[j]=tmp;
      }
    }
  }
  for(i=0;i<N;i++){
    ans+=str[i];
  }
  cout << ans << endl;

  return 0;
}


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

int main()
{
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) 
		if (2 * i < m + 2) printf("%d %d\n", i, m + 2 - i);
	for (int i = 1; i <= m; ++i) 
		if (2 * i < m + 1) printf("%d %d\n", m + 1 + i, 2 * m + 2 - i);
	return 0;
}


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

int main(void)
{
    int n;
    vector<int> nums;
    vector<bool> signs;
    vector<int> plus;
    vector<int> minus;
    int sum;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int buf;
        cin >> buf;
        nums.push_back(buf);
    }
    sort(nums.begin(), nums.end());
    for (int i = 0; i < n; ++i)
    {
        if (i == 0)
        {
            signs.push_back(false);
            minus.push_back(nums[i]);
        }
        else if (i == n - 1)
        {
            signs.push_back(true);
            plus.push_back(nums[i]);
        }
        else
        {
            if (nums[i] >= 0)
            {
                signs.push_back(true);
                plus.push_back(nums[i]);
            }
            else
            {
                signs.push_back(false);
                minus.push_back(nums[i]);
            }
        }
    }
    sum = 0;
    for (int i = 0; i < n; ++i)
    {
        sum += signs[i] ? nums[i] : -nums[i];
    }
    cout << sum << endl;
    int mins0 = minus[minus.size() - 1];
    for (int i = plus.size() - 1; i > 0; --i)
    {
        cout << mins0 << " " << plus[i] << endl;
        mins0 -= plus[i];
    }
    int plu0 = plus[0];
    for (int i = 0; i < minus.size() - 1; ++i)
    {
        cout << plu0 << " " << minus[i] << endl;
        plu0 -= minus[i];
    }
    cout << plu0 << " " << mins0 << endl;
}

Measured memory_bytes: 2840
#include <iostream>
#include <map>
using namespace std;
#include <algorithm>
#include <functional>
int main() {
  string S,T;
  cin >> S >> T;
  //int X[26] = {};//Sの成分
  //int Y[26] = {};//Tの成分
  map<char,char> mp;
  //char alphabet[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  bool isChangable = true;
  if(S.size() != T.size()){
    isChangable = false;
  }else{
    for(int i = 0; i < S.size(); i++){
        auto itr = mp.find(S[i]);
        if(itr == mp.end()){
          mp[S[i]] = T[i];
        }else{
          if(mp[S[i]]!=T[i]){
            isChangable = false;
          }
        }
      }
      mp.clear();
      for(int i = 0; i < T.size(); i++){
          auto itr = mp.find(T[i]);
          if(itr == mp.end()){
            mp[T[i]] = S[i];
          }else{
            if(mp[T[i]]!=S[i]){
              isChangable = false;
            }
          }
        }
    }
    if(isChangable){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }

Measured memory_bytes: 776
while True:
    n, r = map(int, input().split())
    if n == 0 and r == 0:
        break

    card = [i for i in range(n, 0, -1)]
    for i in range(r):
        p, c = map(int, input().split())
        p -= 1
        card = card[p:p + c] + card[:p] + card[p + c:]
        #print(card)

    print(card[0])


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

using namespace std;

#define endl '\n'

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll mod = 1e9 + 7;

ll add(ll a, ll b, ll M){
	return (a + b) % M;
}

ll mul(ll a, ll b, ll M){
	return (a * b) % M;
}

mat eye(int n)
{
	mat I(n, vec(n));
	for (int i = 0; i < n; ++i)
		I[i][i] = 1;
	return I;
}

mat mul(mat A, mat B, ll M)
{
	int l = A.size(), m = B.size(), n = B[0].size();
	mat C(l, vec(n));
	for (int i = 0; i < l; ++i)
		for (int k = 0; k < m; ++k)
			for (int j = 0; j < n; ++j)
				C[i][j] = add(C[i][j], mul(A[i][k], B[k][j], M), M);
	return C;
}

mat pow(mat A, ll b, ll M)
{
	mat X = eye(A.size());
	for (; b > 0; b >>= 1)
	{
		if (b & 1) X = mul(X, A, M);
		A = mul(A, A, M);
	}
	return X;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	ll k;
	cin >> n >> k;
	
	mat A(n, vec(n));
	
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			cin >> A[i][j];
	
	A = pow(A, k, mod);
	
	ll ans = 0;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			ans = add(ans, A[i][j], mod);
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384