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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

void make_match(vector<bool>& match, string const& a, string const& b) {
  rep(i, 2020) {
    rep(j, b.size()) {
      match[i] = match[i] && (a.size() <= i + j || a[i + j] == b[j] || a[i + j] == '?' || b[j] == '?');
    }
  }
}

int solve(string const& a, string const& b, string const& c) {
  vector<bool> match_ab(6060, true);
  vector<bool> match_bc(6060, true);
  vector<bool> match_ac(6060, true);

  make_match(match_ab, a, b);
  make_match(match_bc, b, c);
  make_match(match_ac, a, c);

  int ans = inf;
  rep(i, 2020) {
    rep(j, 2020) {
      if (match_ab[i] && match_bc[j] && match_ac[i + j]) {
        ans = std::min(ans, std::max({(int)a.size(), (int)b.size() + i, i + j + (int)c.size()}));
      }
    }
  }
  return ans;
}

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  auto ans = std::min({solve(a, b, c), solve(a, c, b), solve(b, a, c), solve(b, c, a), solve(c, a, b), solve(c, b, a)});
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(int (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(int (i)=(a)-1;(i)>=(b);(i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define VI vector<int>
#define VII vector<VI>
#define VL vector<LL>
#define VLL vector<VL>
#define VD vector<double>
#define VDD vector<VD>
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<LL,LL>
#define VPII vector<PII>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EP emplace_back
#define FORE(a,b) for(auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9;
const int MOD=INF+7;

// int main(void){
//     string s; cin>>s;
//     map<char,int> mp;
//     REP(i,s.size()){
//         FOR(j,i,s.size()){
//             mp[s[j]]++;
//             if(j>i && mp[s[j]]*2>j-i+1){
//                 cout<<i+1<<" "<<j+1<<endl;
//                 return 0;
//             }
//         }
//         mp.clear();
//     }
//     cout<<-1<<" "<<-1<<endl;
// }


int main(){
    string s; cin>>s;
    map<char,int> mp;
    if(s.size()==2){
        if(s[0]==s[1]){
            cout<<1<<" "<<2<<endl;
            return 0;
        }else{
            cout<<-1<<" "<<-1<<endl;
            return 0;
        }
    }
    REP(i,s.size()-2){
        REP(j,5){
            if(i+j>=s.size()) break;
            mp[s[i+j]]++;
            if(j && mp[s[i+j]]*2>j+1){
                cout<<i+1<<" "<<i+1+j<<endl;
                return 0;
            }
        }
        mp.clear();
    }
    cout<<-1<<" "<<-1<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int ggcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,m,a,b;
  cin>>n>>m;
  vector<int> v(m),w(m);
  rep(i,m) cin>>v[i]>>w[i];
  a=v[0];
  b=w[0];
  rep(i,m){
    a=max(a,v[i]);
    b=min(b,w[i]);
  }
  if(b-a>=0){
    cout<<b-a+1<<endl;
  }else{
    cout<<0<<endl;
  }
}
///////////////////////////

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long x = Long.parseLong(sc.next());
		sc.close();
		long count = b / x - a / x;
		System.out.println(a % x == 0 ? count + 1 : count);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
int main(void){
std::vector<int> wei(11);
  int r,d,fwei;
  std::cin>> r >> d >> fwei;
  wei.at(0)=fwei;
  for(int i=1;i<11;i++){
  wei.at(i)=r*wei.at(i-1)-d;
  }
  for(int j=1;j<11;j++){
  std::cout<< wei.at(j) <<std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long i,j,a[1000000],f[1000000],n;
int main()
    {
        cin>>n;
        for (i=1;i<=n;i++) cin>>a[i];
        f[2]=abs(a[2]-a[1]);
        for (i=3;i<=n;i++)
            f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));

        cout<<f[n];
        return 0;
    }


Measured memory_bytes: 5120
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod=(10**9 + 7)):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


def main():
    N = int(input())
    A = li_input()

    C = Combination(N + 1)

    double_elem = sum(A) - sigma(N)

    l, r = -1, -1

    for i, a in enumerate(A, start=1):
        if a == double_elem:
            if l == -1:
                l = i
            else:
                r = i
                break

    for i in range(1, N + 2):
        print((C(N + 1, i) - C(l - 1 + N + 1 - r, i - 1)) % (10**9 + 7))


main()


Measured memory_bytes: 23736
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    REP(i,n){
        ans += (in() >= k);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 892
// D - Replacing
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	map<int, int> C;
	long long s = 0;
	while(N--){
		int a; cin>>a;
		C[a]++;
		s += a;
	}
	int Q; cin>>Q;
	while(Q--){
		int b, c; cin>>b>>c;
		s += (c - b) * C[b];
		C[c] += C[b];
		C[b] = 0;
		cout<< s << endl;
	}
}


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

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var n = int.Parse(s[0]);
            var r = int.Parse(s[1]);

            if(n >= 10){
                Console.WriteLine(r);
            }else{
                var x = r + (100 * (10 - n));
                Console.WriteLine(x);
            }
        }
    }
}


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

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define endl "\n"
#define E "\n"
#define show(arr) REP(i,arr.size()){cout<<arr[i]<<" ";}
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

#define N 5010

int sum(int x)
{
    int sum = 0;
    while (x>0){
        sum += x%10;
        x/=10;
    }
    return sum;
}

void solve()
{
    int a,b,c,d,e;
    cin>>a>>b>>c;
    if (a==b&&b==c&&a%2==0){
        cout<<-1;
    }
    else {
        int ind=0;
        while(a%2==0 && b%2==0 && c%2==0){
            d=a;
            e=b;
            a=b/2+c/2;
            b=d/2+c/2;
            c=d/2+e/2;
            ind++;
        }
        cout<<ind;
    }
}

signed main()
{
    int t=1;
    //cin>>t;
    WL(t)solve();

    return 0;
}




Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++) 
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int main() 
{
	ios::sync_with_stdio(false);cin.tie(0);
	int n,k;
	cin>>n>>k;
	int ans=1;
	while(n>=k) {
		ans++;
		n/=k;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
using namespace std;
long long n,ans,a,b,sum,mi;
#define inf 1000000005
int main()
{
	scanf("%lld",&n);
	mi=inf;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a,&b);
		sum+=a;
		if(a>b)
			mi=min(mi,b);
	}
	printf("%lld\n",mi==inf?0:sum-mi);
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())

    D1 = T1 * A1 + T2 * A2
    D2 = T1 * B1 + T2 * B2

    if D1 == D2:
        print('infinity')
    else:
        if D2 > D1:
            A1, B1 = B1, A1
            A2, B2 = B2, A2
            D1, D2 = D2, D1
        M1 = T1 * A1
        M2 = T1 * B1
        if M1 > M2:
            print(0)
        else:
            cnt = (M2 - M1) // (D1 - D2)
            ans = cnt * 2
            diff = (M2 - M1) % (D1 - D2)
            if diff > 0:
                ans += 1
            print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61876
#include <cstdio>
#include <vector>

void readInput(std::vector<int>& numList) {
    int size = 0;
    scanf("%d", &size);

    numList.resize(size);

    for (size_t i = 0; i < numList.size(); ++i) {
        int num = 0;
        scanf("%d", &num);
        numList[i] = num;
    }
}

int bubbleSort(std::vector<int>& numList) {
    int swapCount = 0;
    bool next = true;

    while (next) {
        next = false;
        for (size_t i = numList.size() - 1; i >= 1; --i) {
            if (numList[i] < numList[i - 1]) {
                int tmp = numList[i];
                numList[i] = numList[i - 1];
                numList[i - 1] = tmp;
                next = true;
                ++swapCount;
            }
        }
    }

    return swapCount;
}

int main() {
    
    std::vector<int> numList;

    readInput(numList);
    int swapCount = bubbleSort(numList);

    for (size_t i = 0; i < numList.size() - 1; ++i) {
        printf("%d ", numList[i]);
    }
    printf("%d\n%d\n", numList.back(), swapCount);

}


Measured memory_bytes: 2740
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var Vi = Sarray();
            var Ci = Sarray();
            WriteLine(Vi.Zip(Ci, (v, c) => v - c).Where(v => 0 < v).Sum());
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 28260
n = int(input())
v = [int(i) for i in input().split()]


def gcd(x, y):
    if y > x:
        x, y = y, x
    if y == 0:
        return x
    if x % y == 0:
        return y
    return gcd(y, x % y)


l = [0 for i in range(n)]
r = [0 for i in range(n)]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
    r[-i-1] = gcd(r[-i], v[-i])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))


Measured memory_bytes: 14428
N = int(input())
A = list(map(int, input().split()))
B = A.copy()

count = 0
for i in range(N):
    if B[i] < 0:
        count += 1
        B[i] *= -1
  
res = 0
if count%2 == 1:
    B.sort()
    for i in range(1, N):
        res += abs(B[i])

    res -= B[0]
else:
    for i in range(N):
        res += abs(B[i])
        
print(res)

            

Measured memory_bytes: 14224
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

using llint = long long int;
using u64 = std::uint_fast64_t;

void solve(void){

  int n;
  std::string C;
  std::cin >> n >> C;
  int leftW = 0;
  int rightR = n;

  int cnt = 0;

  while(true){
    //std::cout << leftW << " " << rightR << std::endl;
    while(C[leftW]    != 'W' && leftW < n-1) leftW++;
    while(C[rightR-1] != 'R' && rightR > 1) rightR--;
    if(leftW >= rightR - 1) break;

    C[leftW] = 'R';
    C[rightR-1] = 'W';
    cnt++;
  }
  std::cout << cnt << std::endl;
  
}
int main(void){
  solve();
  return 0;
}





Measured memory_bytes: 3764
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  lint A[N];
  REP(i,N)cin>>A[i];
  lint ans=0;
  while(1){
    lint temp=0;
    REP(i,N){
      lint k=A[i]/N;
      temp+=k;
      A[i]%=N;
      REP(j,N){
        if(i==j)continue;
        A[j]+=k;
      }
    }
    // REP(i,N)cerr<<A[i]<<" ";
    // cerr<<endl;
    if(temp==0)break;
    ans+=temp;
  }

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


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

using namespace std;
int main()
{
    int N;
    int a[110];
    int ave=0;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> a[i];
        ave+=a[i];
    }
    ave/=N;

    int sum1=0,sum2=0;
    for(int i=0; i<N; i++){
        sum1+=pow((a[i]-ave),2);
        sum2+=pow((a[i]-(ave+1)),2);
    }

    if(sum1<sum2){
        cout << sum1 << endl;
    }
    else cout << sum2 << endl;

    return 0;
}


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

int n;
int h[105];

int f(void)
{

    int i = 0;
    while (i < n && h[i] == 0) {
        i++;
    }

    return i == n;
}

int main()
{
   
    int l, r;
    int ans = 0;

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

    while (!f()) {
        l=0;
        while(h[l] <= 0) {
            l++;
        }

        r=l;
        while(h[r] > 0) {
            r++;
        }

        for (int i = l; i < r; i++) {
            h[i]--;
        }

        ans++;
    }

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

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll inf=1e18;
const long double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
const double pi=acos(-1);

string s;
int main(){
	TB
	int n,a,b;
    cin>>s;
    if(s.length()<6) cout<<"No\n";
    else if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;


int main(){
    int a;    cin >> a ;

    if(a<10){
        cout << "Yes" << endl;
        return 0;
    }

    for(int i=2;i<10;i++){
        if(a%i == 0 && a/i<10){
             cout << "Yes" << endl;
             return 0;
        }
    }

    cout << "No" << endl;

}




Measured memory_bytes: 256
#include<cstdio>
using namespace std;
typedef long long int ll;

int A, B, K;

int main(){
	scanf("%d %d %d", &A, &B, &K);
	int cnt = 0;
	for(int i = 100; i >= 1; i--){
		if(A % i == 0 && B % i == 0) cnt++;
		if(cnt == K){
			printf("%d\n", i);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 128
n, q = gets.split.map(&:to_i)

tree = Array.new(n) { [] }
(n - 1).times do
  a, b = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  tree[a] << b
  tree[b] << a
end
cnt = Array.new(n, 0)
q.times do 
  pi, xi = gets.split.map(&:to_i)
  pi -= 1
  cnt[pi] += xi
end

que = []
que << [0, 0] # node_id, cnt
ans = []
visited = []
while !que.empty?
  node, c = que.shift
  ans[node] = c + cnt[node]
  visited[node] = true
  if !tree[node].empty?
    tree[node].each do |child_node|
      que << [child_node, c + cnt[node]] if !visited[child_node]
    end
  end
end
puts ans * ' '

__END__
3 3
1 3
2 3
1 1
2 1
3 1

Measured memory_bytes: 37812
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();
    int m = sc.nextInt();
    int hm = h*60+m;
    double ha = 0.5*hm;
    double ma = 6.0*m;
    double angle = Math.abs(ha-ma);
    if (angle>=180){
      angle=360-angle;
    }
    double c = 0;
    c=Math.sqrt(a*a+b*b-2*a*b*Math.cos(Math.toRadians(angle)));
    System.out.println(c);
  }
}

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


int sb[6]={60,80,100,120,140,160};
int wb[6]={2,5,10,15,20,25};

int main(){
	int n;
	while(cin>>n&&n){
		int s=0;
		for(int i=0;i<n;i++){
			int x,y,h,w;
			cin>>x>>y>>h>>w;
			int a,b;
			a=lower_bound(sb,sb+6,x+y+h)-sb;
			b=lower_bound(wb,wb+6,w)-wb;
			if(a==6||b==6)continue;
			s+=600+200*max(a,b);
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
def main():
    n = int(input())
    l = list(map(int, input().split()))
    fumidai_sum = 0
    last = 0
    for i, ai in enumerate(l):
        if last > ai:
            diff = last - ai
            fumidai_sum += diff
            last = ai + diff
        else:
            last = ai
            continue
    print(fumidai_sum)


if __name__ == '__main__':
    main()


Measured memory_bytes: 105308
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<string>
#include<cmath>
using namespace std;
const double eps=1e-16;
int main(){
	int n,t,A;
	cin>>n>>t>>A;
	int h[100005];
	double T[100005];
	int ans=1;
	for(int i=1;i<=n;i++){
		cin>>h[i];
		T[i]=t-h[i]*0.006;
		if(fabs(T[i]-A)<fabs(T[ans]-A)){
			ans=i;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N;

    scanf("%d", &N);

    int a[N];

    for(int i = 0; i < N; i++){
        scanf("%d", &a[i]);
    }

    int c, min = 1000000000;

    for(int i = -100; i <= 100; i++){
        c = 0;
        for(int j = 0; j < N; j++){
            c += (a[j] - i) * (a[j] - i);
        }
        if(c < min){
            min = c;
        }
    }

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

    return 0;
}

Measured memory_bytes: 1732
#include<iostream>

using namespace std;

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX/2 + 1], R[MAX/2 + 1];

llong merge(int A[], int left, int mid, int right) {
  int i, j, k;
  llong cnt = 0;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i = 0; i < n1; i++) L[i] = A[left + i];
  for(i = 0; i < n2; i++) R[i] = A[mid + i];

  L[n1] = R[n2] = SENTINEL;

  i = j = 0;

  for(k = left; k < right; k++) {
    if(L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
      cnt += n1 - i;
    }
  }
  return cnt;
}

llong mergeSort(int A[], int left, int right) {
  int mid;
  llong v1, v2, v3;
  if(left + 1 < right) {
    mid = (right + left) / 2;
    v1 = mergeSort(A, left, mid);
    v2 = mergeSort(A, mid, right);
    v3 = merge(A, left, mid, right);
    return v1 + v2 + v3;
  } else return 0;
}

int main() {
  int A[MAX], n, i;
  cin >> n;
  for(i = 0; i < n; i++) {
    cin >> A[i];
  }

  llong ans = mergeSort(A, 0, n);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 4632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allg(v) v.begin(), v.end(), greater<int>()



signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, a, b, c, d, e, mini = 10000000000000000;
  cin >> n >> a >> b >> c >> d >> e;
  if(a==b and b==c and c==d and d==e)
    mini = a;
  else 
    mini = min(min(min(min(min(a, b), c), d), e), mini);
      
  cout << 4+ (n+mini-1)/mini << "\n";

}

Measured memory_bytes: 256
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    for0(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    nl     "\n"
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long int
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;

int a[5],f;
for(int i=0;i<5;i++)cin>>a[i];
for(int i=0;i<5;i++){
    if(a[i]==0){
        f=i;
        break;
    }
}
cout<<f+1;
End;   
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> array(n);
    for(int i=0;i<n;i++) cin >> array.at(i);
    sort(array.begin(),array.end(),greater<int>());
    ll sum=0;
    for(int i=1; i<n; i++){
        int index = i / 2;
        sum += array.at(index);
        
    }
    cout << sum << endl;
}



Measured memory_bytes: 4052
#include<iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a==b)cout << "Draw\n";
    else if(a==1)cout << "Alice\n";
    else if(b==1)cout << "Bob\n";
    else if(a>b)cout << "Alice\n";
    else cout << "Bob\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	// no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} 
using io :: gi;
using io :: putc;
using io :: print;
const int N=5005,mod=1e9+7,inv2=mod+1>>1;
int tot,head[N],nxt[N<<1],adj[N<<1],f[N][N],sz[N],dp[N],fac[N],ifac[N],powerinv[N];
inline void addedge(ri x,ri y){
	nxt[++tot]=head[x];
	adj[head[x]=tot]=y;
}
inline int fpow(ri a,ri b){
	ri ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1) ans=(ll)ans*a%mod;
	return ans;
}
inline int C(ri n,ri m){
	return m<0||n<m?0:(ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
inline int calc(ri x){
	return (ll)C(x,x>>1)*fac[x>>1]%mod*powerinv[x>>1]%mod;
}
inline void dfs(ri x,ri fa){
	f[x][1]=1;
	sz[x]=1;
	ri y,i,j,k;
	for(i=head[x];i;i=nxt[i])
		if((y=adj[i])!=fa){
			dfs(y,x);
			for(j=sz[x]+sz[y];j>=0;--j)
				dp[j]=0;
			for(j=1;j<=sz[x];++j)
				for(k=0;k<=sz[y];++k)
					dp[j+k]=(dp[j+k]+(ll)f[x][j]*f[y][k])%mod;
			sz[x]+=sz[y];
			for(j=0;j<=sz[x];++j)
				f[x][j]=dp[j];
		}
	if(x==1)
		for(i=2;i<=sz[x];i+=2)
			f[x][0]=(f[x][0]+(ll)calc(i)*f[x][i])%mod;
	else
		for(i=2;i<=sz[x];i+=2)
			f[x][0]=(f[x][0]+(ll)(mod-calc(i))*f[x][i])%mod;
//	for(i=0;i<=sz[x];++i)
//		if(f[x][i])
//			printf("f %d %d %d\n",x,i,f[x][i]);
}
int main(){
	ri n,i,x,y;
	gi(n);
	fac[0]=1;
	for(i=1;i<=n;++i) fac[i]=(ll)fac[i-1]*i%mod;
	ifac[n]=fpow(fac[n],mod-2);
	for(i=n;i;--i) ifac[i-1]=(ll)ifac[i]*i%mod;
	powerinv[0]=1;
	for(i=1;i<=n;++i) powerinv[i]=(ll)powerinv[i-1]*inv2%mod;
	for(i=1;i^n;++i) gi(x),gi(y),addedge(x,y),addedge(y,x);
	dfs(1,0);
	printf("%d\n",f[1][0]);
	return 0;
}

Measured memory_bytes: 99968
#include<bits/stdc++.h>
using namespace std;
int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int flag=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]==s[i+1]){
            cout<<i+1<<" "<<i+2<<endl;
            flag=1;
            break;
        }
        else if(i<s.size()-2&&s[i]==s[i+2]){
            cout<<i+1<<" "<<i+3<<endl;
            flag=1;
            break;
        }
    }
    if(!flag)
    cout<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 512
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7



n, a, b = MAP()

ans = a * (n // (a + b))
n -= (a + b) * (n // (a + b))
ans += min(a, n)

print(ans)

Measured memory_bytes: 5444
slist=list(input())
kosu=[]
n=len(slist)
counter=1
for i in range(n-1):
	if slist[i]==slist[i+1]:
		counter+=1
	else:
		kosu.append(counter)
		counter=1
kosu.append(counter)

nagasa=len(kosu)
kotae=0
if nagasa==1:
	kotae=kosu[0]*(kosu[0]+1)/2
else:
	if slist[0]=="<":
		if nagasa%2==0:
			for i in range(0,nagasa,2):
				kotae+=(kosu[i]*(kosu[i]+1)+kosu[i+1]*(kosu[i+1]+1))/2-min(kosu[i],kosu[i+1])
		else:
			for i in range(0,nagasa-1,2):
				kotae+=(kosu[i]*(kosu[i]+1)+kosu[i+1]*(kosu[i+1]+1))/2-min(kosu[i],kosu[i+1])
			kotae+=kosu[-1]*(kosu[-1]+1)/2
	else:
		if nagasa%2!=0:
			for i in range(1,nagasa,2):
				kotae+=(kosu[i]*(kosu[i]+1)+kosu[i+1]*(kosu[i+1]+1))/2-min(kosu[i],kosu[i+1])
			kotae+=kosu[0]*(kosu[0]+1)/2
		else:
			for i in range(1,nagasa-1,2):
				kotae+=(kosu[i]*(kosu[i]+1)+kosu[i+1]*(kosu[i+1]+1))/2-min(kosu[i],kosu[i+1])
			kotae+=kosu[0]*(kosu[0]+1)/2
			kotae+=kosu[-1]*(kosu[-1]+1)/2
kotae=int(kotae)
print(kotae)
	

Measured memory_bytes: 9776
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int mod = 1000000007;
const int INF = 1e9;

int tb[256];
int td[256];
bool zeroF[256];

bool f[10];

vector<int> d;

int dfs(int m){
	if (d.size() == m){
		int tmp = 0;
		rep(i, d.size()){
			tmp += td[d[i]] * tb[d[i]];
		}
		return (tmp ? 0 : 1);
	}
	int ret = 0;

	for (int i = 0; i <= 9; i++){
		if (f[i] == false && (i != 0 || !zeroF[d[m]])){
			tb[d[m]] = i;
			f[i] = true;
			ret += dfs(m + 1);
			f[i] = false;
		}
	}
	return ret;
}

int main()
{
	int n;

	while (cin >> n && n){
		clr(tb);
		clr(td);
		clr(zeroF);
		d.clear();

		set<char> se;
		rep(i, n){
			string s;
			cin >> s;
			rep(j, s.size()){
				if (s.size() != 1 && j == 0){
					zeroF[s[j]] = true;
				}
				se.insert(s[j]);

				if (i == n - 1){
					td[s[j]] -= pow(10, s.size() - j - 1);
				}
				else{
					td[s[j]] += pow(10, s.size() - j - 1);
				}
			}
		}
		for (auto i : se){
			d.push_back(i);
		}

		cout << dfs(0) << endl;
	}
	return 0;
}

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

typedef long long ll;

int main()
{
    int i,j,k;
    int h,w;
    cin >> h >> w;
    vector<string> maze(h);
    for(i = 0;i < h;++i){
        cin >> maze.at(i);
    }
    vector<int> ans;
    for(i = 0;i < h;++i){
        for(j = 0;j < w;++j){
            if(maze.at(i).at(j) == '#'){
                continue;
            }
            int temp_max = 0;
            int temp_num = 0;
            vector<vector<int>> num(h,vector<int>(w,-1));
            queue<pair<int,int>> que;
            que.emplace(i,j);
            num.at(i).at(j) = 0;
            int tate[4] = {0,1,0,-1};
            int yoko[4] = {1,0,-1,0};
            while(!que.empty()){
                int temp_i = que.front().first;
                int temp_j = que.front().second;
                que.pop();
                temp_num = num.at(temp_i).at(temp_j);
                if(temp_num > temp_max){
                    temp_max = temp_num;
                }

                for(k = 0;k < 4;++k){
                    int temp_t = temp_i + tate[k];
                    int temp_y = temp_j + yoko[k];
                    if(temp_t < 0 || temp_t >= h){
                        continue;
                    }else if(temp_y < 0 || temp_y >= w){
                        continue;
                    }else if(maze.at(temp_t).at(temp_y) == '#'){
                        continue;
                    }
                    if(num.at(temp_t).at(temp_y) == -1){
                        que.emplace(temp_t,temp_y);
                        num.at(temp_t).at(temp_y) = temp_num+1;
                    }
                }
            }
            ans.push_back(temp_max);
        }
    }
    sort(ans.begin(),ans.end());
    cout << ans.back() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
 
int main() {
  string n;
  cin >> n;
  int ans =0;
  int x = atoi(n.c_str());
  
  if(n.size()%2==0){
    for(int i=1;i<n.size();i+=2)
      ans = ans + pow(10,i) - pow(10,i-1);
  }
  else{
    for(int i=1;i<=n.size();i+=2){
      if(x>=pow(10,i))
        ans = ans + pow(10,i) - pow(10,i-1);
      else
        ans = ans + x + 1 - pow(10,i-1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

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



Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int M;
    cin >> M;
    int cnt = 0;
    int cnt2 = 0;
    for(int i = 0; i < M; i++) {
        int d,c;
        cin >> d >> c;
        cnt2+=c;cnt+=d*c;
    }
    cout << cnt2-1+(cnt-1)/9 << endl;
}


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

#define endl "\n"
#define int long long

const int MOD = 1e9 + 7;
const int INF = 2e15;

void debug(vector <int> &dp, int l, int r) {
	for (int i = 1; i <= r; i++) {
		if (dp[i] == INF) cout << "inf ";
		else cout << dp[i] << " ";
	}
	cout << endl;
}

void max_self(int &a, int b) {
	a = max(a, b);
}

void min_self(int &a, int b) {
	a = min(a, b);
}

signed main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	int n, w;
	cin >> n >> w;

	vector <int> dp(w + 1, 0);
	dp[0] = 0;

	while (n--) {
		int cost, value;
		cin >> cost >> value;

		for (int i = w; i >= cost; i--) {
			max_self(dp[i], dp[i - cost] + value);
		}
	}

	cout << dp[w] << endl;

}

Measured memory_bytes: 3992
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


int main() {
	int N, D;
	cin >> N >> D;
	vi d(N);
	rep(i, N) {
		cin >> d[i];
	}
	int Q;
	cin >> Q;
	vi q(Q);
	rep(i, Q) {
		cin >> q[i];
		q[i]--;
	}
	vll pos(N);
	pos[0] = D;
	repl(i, 1, N) {
		pos[i] = min(abs(pos[i - 1] - d[i - 1]), pos[i - 1]);
	}
	vll ng(N);
	ng[N - 1] = 1;
	reprev(i, N - 1) {
		if (ng[i + 1] * 2 <= d[i + 1]) {
			ng[i] = ng[i + 1];
		}
		else {
			ng[i] = ng[i + 1] + d[i + 1];
		}
	}


	rep(i, Q) {
		if (pos[q[i]] >= ng[q[i]]) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 14976
import sys
from math import floor, sqrt

def prime_nums(n):
    sieve = set(range(2, n + 1))
    non_prime = set(range(2 * 2, n + 1, 2))
    sieve -= non_prime
    for i in range(3, floor(sqrt(n)) + 1, 2):
        if i in sieve:
            non_prime = set(range(i * 2, n + 1, i))
            sieve -= non_prime
    return sieve

ps = prime_nums(55555)

cand = []
for p in ps:
    if p % 5 == 1:
        cand.append(p)


n = int(sys.stdin.readline().rstrip())

def main():
    return cand[:n]  

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Measured memory_bytes: 12396
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

#define MAX 200000
typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();

int main(){
    int N;
    int i;
    int max;
    int count;
    string *str;
    int num_of_max;
    string temp;
    string *s;
    cin >> N;
    s = new string[N];
    str = new string[N];
    for(i=0;i<N;i++){
        cin >> s[i];
    }
    sort(s,s+N);
    count = 0;
    num_of_max=0;
    max = 0;
    temp = s[0];
    for(i=0;i<N;i++){
        if(temp == s[i]){
            count++;
            if(i == N-1){
                if( count > max){
                    max = count;
                    num_of_max = 0;
                    str[num_of_max++] = temp;
                }else if(count == max){
                    str[num_of_max++] = temp;
                } 
            }
        }else{
            if( count > max){
                max = count;
                num_of_max = 0;
                str[num_of_max++] = temp;
            }else if(count == max){
                str[num_of_max++] = temp;
            }
            temp = s[i];
            count=1;
            if(i == N-1){
                if( count > max){
                    max = count;
                    num_of_max = 0;
                    str[num_of_max++] = temp;
                }else if(count == max){
                    str[num_of_max++] = temp;
                } 
            }
        }
    }
    for(i=0;i<num_of_max;i++){
        cout << str[i] << endl;
    }
    return 0;
}

void process(){
    
}

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
const int MAXN=1e6+10;
vector<vector<int> >lista_susjedstva;
int najduzi[MAXN];
int dfs(int node)
{
    int maxi=0;
    for (int i=0; i<lista_susjedstva[node].size(); ++i)
    {
        if (najduzi[node]!=-1)
            maxi=max(maxi, najduzi[lista_susjedstva[node][i]]+1);
        else
            maxi=max(maxi, dfs(lista_susjedstva[node][i])+1);
    }
    najduzi[node]=maxi;
    return maxi;
}
int main()
{
    int n, m;
    cin >>n>>m;
    lista_susjedstva.resize(n);
    memset(najduzi, -1, sizeof(najduzi));
    for (int i=0; i<m; ++i)
    {
        int x, y;
        cin >>x>>y;
        --x;
        --y;
        lista_susjedstva[y].push_back(x);
    }
    int maxi=0;
    for (int i=0; i<n; ++i)
    {
        if (najduzi[i]==-1)
            dfs(i);
        maxi=max(maxi, najduzi[i]);
    }
    cout <<maxi;
    return 0;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int a,b,n,x;
  cin >> a >> b >> n;
  if(b>n)
    x = n;
  else
    x = b-1;
  cout << ((a*x)/b)-a*(x/b) << endl;
  return 0;
}
  

Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        int x;
        cin >> x;
        a[x-1]++;
    }
    sort(a.begin(), a.end());
    vector<int> s(n+1);
    rep(i, n) s[i+1] = s[i] + a[i];
    for (int k = 1; k <= n; k++){
        int l = 0, r = n / k + 1; // l:OK, r:NG
        while(l + 1 < r){
            int c = (l + r) / 2;
            bool ok = [&](int c){
                int i = lower_bound(a.begin(), a.end(), c) - a.begin();
                int sum = c * (n - i) + s[i];
                return (sum >= c * k);
            }(c);
            if(ok) l = c; else r = c;
        }
        printf("%d\n", l);
    }
}

Measured memory_bytes: 5632
n,m,X,Y = gets.split.map(&:to_i)
x = gets.split.map(&:to_i).sort
y = gets.split.map(&:to_i).sort
ans = false
for i in X+1..Y
  if x[-1] < i && y[0] >= i
    ans = true
  end
end
puts ans ? "No War" : "War"

Measured memory_bytes: 1788
package main

import (
	"fmt"
	"os"
)

func main() {
	var r, g, b int
	fmt.Fscanf(os.Stdin, "%d %d %d", &r, &g, &b)
	n := r * 100 + g * 10 + b
	if n % 4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var x = Input.NextLong();

            Console.WriteLine(((x - 1) / 11 + 1) * 2 - Convert.ToInt64(x % 11 <= 6 && x % 11 > 0));
        }
    }

    class Input {
        static IEnumerator<string> enumerator;

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            if (enumerator == null || !enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
                enumerator.MoveNext();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            if (enumerator == null || !enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
                enumerator.MoveNext();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268