akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
long* partition(long* target, int left, int right) {
// Select a number between left and right at random.
long random = left+(rand()%(right-left));
// Exchange target[right] and target[random].
long tmp = target[right]; target[right] = target[random]; target[random] = tmp;

long pivot = target[right];
int i = left-1; // i scans the array from the left.
int j = right; // j scans the array from the right.
int pvr =right-1;
int pvf = left;
int countr=0;
int countl=0;
long* returner = (long*)malloc(2);
for (;;) {
// Move from the left until hitting a value no less than the pivot.
for(i++; target[i] <= pivot&&i<right; i++){
  if(target[i]==pivot)
  {
    target[i]=target[pvf];
    target[pvf]=pivot;
    pvf++;
    countl++;
  }
}
// Move from the right until hitting a value no greater than the pivot.
for(j--; pivot <= target[j] && i <= j; j--){
  if(target[j]==pivot)
  {
    target[j]=target[pvr];
    target[pvr]=pivot;
    pvr--;
    countr++;
  }
}
if (i >= j) break;
// Exchange target[i] and target[j]
tmp = target[i]; target[i] = target[j]; target[j] = tmp;

}
// Exchange target[i] and target[right].

for(int k=0;k<countl;k++)
{
  target[left+k]=target[j-k];
  target[j-k]=pivot;
}
for(int l=countr;l>=0;l--)
{
  target[right-l]=target[j+1+l];
  target[j+1+l]=pivot;
}
returner[0]=j-countl;
returner[1]=j+countr+2;
return returner;}

void randomQuickSort1(long* target, int left, int right ) {
if (left < right) {
long *i = partition(target, left, right);
 // i: Position of the pivot.
randomQuickSort1(target, left, i[0] );
randomQuickSort1(target, i[1] , right);
}
}

int main(void)
{
  int size;
  int selectsize;
  cin>>size>>selectsize;
  long cakes[size][3];
  long table1[size];
  long table2[size];
  long table3[size];
  long table4[size];
  long table5[size];
  long table6[size];
  long table7[size];
  long table8[size];

  for(int i=0;i<size;i++)
  {
    cin>>cakes[i][0]>>cakes[i][1]>>cakes[i][2];
    table1[i]=cakes[i][0]+cakes[i][1]+cakes[i][2];
    table2[i]=cakes[i][0]+cakes[i][1]-cakes[i][2];
    table3[i]=cakes[i][2]+cakes[i][1]-cakes[i][0];
    table4[i]=cakes[i][0]+cakes[i][2]-cakes[i][1];
    table5[i]=cakes[i][0]-cakes[i][1]-cakes[i][2];
    table6[i]=cakes[i][2]-cakes[i][1]-cakes[i][0];
    table7[i]=cakes[i][1]-cakes[i][0]-cakes[i][2];
    table8[i]=-(cakes[i][0]+cakes[i][1]+cakes[i][2]);
  }
  randomQuickSort1(table1, 0,size-1);
  randomQuickSort1(table2, 0,size-1);
  randomQuickSort1(table3, 0,size-1);
  randomQuickSort1(table4, 0,size-1);
  randomQuickSort1(table5, 0,size-1);
  randomQuickSort1(table6, 0,size-1);
  randomQuickSort1(table7, 0,size-1);
  randomQuickSort1(table8, 0,size-1);
  long score[8]={0};
  for(int i=size-1;i>=size-selectsize;i--)
  {
     score[0]+=table1[i];
     score[1]+=table2[i];
     score[2]+=table3[i];
     score[3]+=table4[i];
     score[4]+=table5[i];
     score[5]+=table6[i];
     score[6]+=table7[i];
     score[7]+=table8[i];
  }
  randomQuickSort1(score, 0,7);
  cout<<score[7];
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};



int main(){
    int h,n;cin >> h >> n;
    for (int i = 0; i < n; i++) {
        int a;cin >> a;
        h -= a;
    }
    if(h <= 0) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define PI 3.141592653589793

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

llong a, b, x;

double solve() {
    if(x > a * a * b / 2.0) {
        double y = 2 * b - 2 * (double)x / (a * a);
        return atan2(y, a) / PI * 180;
    } else {
        double y = 2 * (double)x / (a * b);
        return atan2(b, y) / PI * 180;
    }
}

int main(int argc, char **argv) {
    cin >> a >> b >> x;

    printf("%.10lf\n", solve());
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		
		while(scanner.hasNext()){
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int x =a + b;
			String y = Integer.toString(x);
			System.out.println(y.length());
		}

	}
}

Measured memory_bytes: 26344
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    # S_0はNが奇数の時1で、そうでないとき0にする必要があります
    # 基本的にはNを-2で割って、割った余りを答えに追加していくような感じ。
    # N = (-2)q + r
    # としたときに、rが0か1になるようにqを調節するということになります。
    # Nが偶数ならr = 0
    # Nが奇数ならr = 1
    # 単にNを2で割るのと変わらない
    # N % 2 の値は0か-1になるので、 -1 になるならそれに２を足す
    str_ = ""
    while n != 0:
        # N を2で割ったあまりを求める
        r = n % 2
        if r < 0:
            r += 2 # nがマイナスだと、rがマイナスになったりするので2を足す
        n = (n-r)// (-2)
        # - 2で割る
        str_ += str(r)
    #向きが逆なので反転
    str_ = str_[::-1]
    if str_ == '':
        str_ = '0'
    print(str_)



if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	M, _ := strconv.Atoi(sc.Text())

	works := make(map[int][]int)
	for i := 0; i < N; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())

		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())

		if _, ok := works[a]; !ok {
			works[a] = make([]int, 0)
		}
		works[a] = append(works[a], b)
	}

	result := 0
	h := &IntHeap{}
	heap.Init(h)
	for i := 1; i < M+1; i++ {
		if _, ok := works[i]; ok {
			for j := 0; j < len(works[i]); j++ {
				heap.Push(h, works[i][j])
			}
		}

		if h.Len() > 0 {
			result += heap.Pop(h).(int)
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 12160
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            var first = int.Parse(s.Substring(0, 2));
            var last = int.Parse(s.Substring(2, 2));
            var isYYMM = (0 < last && last < 13);
            var isMMYY = (0 < first && first < 13);
            if (isYYMM)
            {
                if (isMMYY) Console.WriteLine("AMBIGUOUS");
                else Console.WriteLine("YYMM");
            }
            else
            {
                if (isMMYY) Console.WriteLine("MMYY");
                else Console.WriteLine("NA");
            }
        }
    }
}


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

int n;
vector<int> c;
vector<vector<int> > G;
vector<int> ans;
int x = 0;

void dfs(int now, int ago){
 ans[now] = c[x];
 x++;
 for(int i = 0; i < G[now].size(); i++){
   int next = G[now][i];
   if(next == ago) continue;
   dfs(next, now);
 }
}
 
int main(){
  cin >> n;
	G.resize(n);
  for(int i = 0; i < n-1; i++){
    int a,b; scanf("%d%d", &a, &b);
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  int res = 0;
  c.resize(n);
  for(int i = 0; i < n; i++){
    scanf("%d", &c[i]); res += c[i];
  }
  sort(c.begin(),c.end(), greater<int>());
  res -= c[0];
  ans.resize(n);
  dfs(0, -1);
  cout << res << endl;
  for(int i = 0; i < n; i++) cout << ans[i] << " ";
}

Measured memory_bytes: 1408
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,m,k=n1()
A=n1()
B=n1()

AA=list(itertools.accumulate(A))
BB=list(itertools.accumulate(B))

ans=bisect_right(BB,k)

for i in range(n):
    s=k-AA[i]
    if s<0:
        continue
    tmp=bisect_right(BB,s)
#     print(i,tmp,ans)
    ans=max(ans,i+1+tmp)
print(ans)

Measured memory_bytes: 47448
/*input
6 6 8
..##..
.#..#.
#....#
######
#....#
#....#
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll INF64=8e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
ll mult(ll a,ll b){
    a%=MOD;
    b%=MOD;
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=1e5+5;
const ll maxlg=__lg(maxn)+2;
string arr[maxn];
string cur[maxn];
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    REP(i,n) cin>>arr[i];
    int ans=0;
    REP(i,(1<<n)){
        REP(j,(1<<m)){
            REP(z,n) cur[z]=arr[z];
            REP(z,n){
                if(i&(1<<z)){
                    REP(k,m) cur[z][k]='.';
                }
            }
            REP(z,m){
                if(j&(1<<z)){
                    REP(k,n){
                        cur[k][z]='.';
                    }
                }
            }
            int cnt=0;
            REP(z,n){
                REP(k,m) if(cur[z][k]=='#') ++cnt;
            }
            if(cnt==k){
                ++ans;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 9892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=2e5;
const int INF=1e9;
int main(){
	string a;cin>>a;
	if(a=="Sunny") cout<<"Cloudy"<<endl;
	else if(a=="Cloudy") cout<<"Rainy"<<endl;
	else cout<<"Sunny"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD= 1000000007;
signed main() {
int n;
cin>>n;
int c[100]={},a,amax=0;
for(int i=0;i<n;i++){
  cin>>a;
  c[a]++;
  amax=max(amax,a);
}
if(amax%2){
  if(c[(amax+1)/2]!=2){
    cout<<"Impossible";
    return 0;
  }
  for(int i=(amax+1)/2+1;i<=amax;i++){
    if(c[i]<2){
      cout<<"Impossible";
      return 0;
    }
  }
  cout<<"Possible";
  return 0;
}else{
  if(c[(amax)/2]!=1){
    cout<<"Impossible";
    return 0;
  }
  for(int i=(amax)/2+1;i<=amax;i++){
    if(c[i]<2){
      cout<<"Impossible";
      return 0;
    }
  }
  cout<<"Possible";
  return 0;
}
return 0;

}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<pi>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int n, k;
vvi memo;
int A[100];
bool f(int l, int x) {
    if(memo[l][x]!=-1) return memo[l][x];
    bool res = 0;
    rep(i, n) if(A[i]<=l) res|=1^f(l-A[i], x^1);
    memo[l][x] = res;
    return res;
}


int main(){
    cin >> n >> k;
    rep(i, n) cin >> A[i];
    memo.resize(k + 1, vi(2, -1));
    if(f(k, 0)) co("First");
    else co("Second");
}



Measured memory_bytes: 14880
a, b, c = gets.chomp.split.map(&:to_i)
arr = []
sum = 0
while true
    sum += a
    r = sum % b
    case r
    when c
        puts "YES"
        break
    else
        if arr[r] == true
            puts "NO"
            break
        else
            arr[r] = true
        end
    end
end

Measured memory_bytes: 1788
/*
  AOJ 1600
  Title:
  @kankichi573
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int m,nmin,nmax;

int compare_int(const void *a, const void *b)
{
  if( *(int *)a > *(int *)b)
    return(-1);
  if( *(int *)a < *(int *)b)
    return(1);
  if( *(int *)a == *(int *)b)
    return(0);
}



main()
{
  int i,max_,max_p,diff,P[200];
  
  while(scanf("%d %d %d",&m,&nmin,&nmax)  && (m||nmin||nmax))
    {
      memset(P,0,sizeof(P));
      for(i=0;i<m;i++)
	scanf("%d",&P[i]);
      qsort(P,m,sizeof(int),compare_int);
      max_=0;
      for(i=nmin ;i<=nmax;i++)
	{
	  diff=P[i-1]-P[i];
	  //printf("diff=%d\n",diff);
	if(max_ <= diff)
	  {
	    max_  = diff;
	    max_p = i;
	  }
	}
      printf("%d\n",max_p);
      //printf("[%d]\n",max_);
    }
  return(0);
}

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

int main()
{
int n,a=0,s=0,d;
cin>>n;
while(n>=500){
    n-=500;
    a++;
}
while(n>5){
    n-=5;
    s++;
}
d=(1000*a+5*s);
cout<<d;
}

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001;
using namespace std;
typedef long long ll;

int n;
int l[20];

int main(){
  std::cin >> n;
  int l_max = 0;
  int l_sum = 0;
  rep(i,1,n+1){
    std::cin >> l[i];
    l_sum += l[i];
    if(l[i] > l_max)l_max = l[i];
  }
  if(l_max < l_sum-l_max)std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
def cmb(n, r, p):
    return (fac[n] * pow(fac[r], p - 2, p) * pow(fac[n - r], p - 2, p)) % p


p = 998244353
N, M, K = map(int, input().split())
fac = [1] * (max(N, M) + 1)
for i in range(1, max(N, M) + 1):
    fac[i] = (fac[i - 1] * i) % p

ans = 0
for k in range(K + 1):
    ans += M * pow(M - 1, N - k - 1, p) * cmb(N - 1, k, p)
    ans %= p
print(ans)


Measured memory_bytes: 72860
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
int main(){
    vl p;
    p.pb(2);p.pb(3);
    for(int i=4;i<100000;i++){
        bool np=false;
        for(int j=2;j<sqrt(i)+1;j++){
            if(i%j==0){
                np=true;
                break;
            }
        }
        if(!np)p.pb(i);
    }
    vl like;
    rep(i,p.size()){
        for(int j=0;j<i;j++){
            if((p[i]+1)/2==p[j])like.pb(p[i]);
        }
    }
    vl sum(100002);
    ll count=0,check=0;
    rep(i,100002){
        if(like[check]==i){
            count++;
            check++;
        }
        sum[i]=count;
    }
    ll q;cin >> q;
    rep(i,q){
        ll l,r;cin >> l >>r;l--;
        cout << sum[r]-sum[l] <<endl;
    }
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	if (a1 > b1) swap(a1, b1), swap(a2, b2);

	if (a1*t1 + a2*t2 < b1*t1 + b2*t2)
	{
		cout << "0\n";
		return 0;
	}

	if (a1*t1 + a2*t2 == b1*t1 + b2*t2)
	{
		cout << "infinity\n";
		return 0;
	}

	ll l = 1, r = (b1*t1 - a1*t1) / (a1*t1 + a2*t2 - (b1*t1 + b2*t2)) + 1;
	/*debug(r);
	while (l < r)
	{
		ll m = (l+r+1) >> 1;
		if ((a1*t1 + a2*t2 - (b1*t1 + b2*t2)) * (m-1) <= b1*t1 - a1*t1)
			l = m;
		else
			r = m-1;
	}*/

	l = r;
	bool x = (b1*t1 - a1*t1) % (a1*t1 + a2*t2 - (b1*t1 + b2*t2)) == 0;
	l *= 2;
	l -= x;
	cout << l-1 << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <cmath>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

constexpr int LIM = 1000000000000000000;

void solve() {
  int N;
  cin >> N;
  vector<int> A(N);

  for (int &a:A) {
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return;
    }
  }

  int ans = 1;
  for (int a:A) {
    int keta = log10(ans);
    if (keta + log10(a) > 18) {
      ans = -1;
      break;
    }

    ans *= a;
    if (ans > LIM) {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 3668
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  while(cin >> s){
    while(s.find("@")!=-1){
      int x=s.find("@");
      string buf;
      for(int i=0;i<s[x+1]-'0';i++) buf+=s[x+2];
      s.replace(x,3,buf);
    }cout << s << endl;
  }
}


Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const int INF = 100000;

int dp[45][405][405];

int main(void){
    int n, a[45], b[45], c[45], ma, mb, suma = 0, sumb = 0;

    cin >> n >> ma >> mb;
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
        suma += a[i]; sumb += b[i];
    }

    for (int i = 0; i <= suma; i++)
        for (int j = 0; j <= sumb; j++) dp[0][i][j] = INF;

    dp[0][0][0] = 0;

    for (int i = 0; i < n; i++){
        for (int j = 0; j <= suma; j++){
            for (int k = 0; k <= sumb; k++){
                dp[i + 1][j][k] = dp[i][j][k];
                if (a[i] <= j && b[i] <= k) dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
            }
        }
    }

    int ans = INF;
    for (int i = 1; i <= suma; i++){
        for (int j = 1; j <= sumb; j++){
            if (ma*j == mb*i) ans = min(ans, dp[n][i][j]);
        }
    }

    if (ans == INF) ans = -1;
    cout << ans << endl;

}

Measured memory_bytes: 26240
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"Yes"<<endl
#define cno cout<<"No"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

ll A(ll n,ll a,ll b){
    return n*a*b;
}
ll B(ll n,ll a,ll b){
    return 4*a*b - (a+b)*n;
}

int main(){

    ll N; cin >> N;
    ll h,n,w;
    for(ll a = 1; a <= 3500; a++)for(ll b = 1; b <= 3500; b++){
        if(B(N,a,b)<=0) continue;
        if(A(N,a,b) < B(N,a,b)) continue;
        if(A(N,a,b)%B(N,a,b) == 0){
            h = a;
            w = b;
            n = A(N,a,b)/B(N,a,b);
            break;
        }
    }    
    cout << h sp w sp n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,a[210000],anst,ans[210000];
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	fd(i,n,1)
		for(int j=i+i;j<=n;j+=i) a[i]^=a[j];
	fo(i,1,n) if (a[i]) ans[++anst]=i;
	printf("%d\n",anst);
	fo(i,1,anst) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=1e6+5; 
 
int main(){
	string s;
	cin>>s;
	ll sum=0;
	for(int i=0;i<(int)s.size();i++)
	sum+=s[i]-'0';
	if(sum%9==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
} 

Measured memory_bytes: 3672
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int u500 =0, u5 =0;
    u500 = X / 500 * 1000;
    u5 = X % 500 / 5 * 5;
    System.out.println(u500 + u5);
  }
}

Measured memory_bytes: 22740
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace number_of_island
{
    class Program
    {
        static void Main(string[] args)
        {
            var map_temp = new List<string>();
            var map_arry = new List<See_map>();
            string read;
            while (true)
            {
                map_temp.Clear();
                for (var i = 0; i < 12; i++)
                    map_temp.Add(Console.ReadLine());

                map_arry.Add(new See_map(map_temp));

                read = Console.ReadLine();
                if (read==null) break;


            }
            foreach(See_map map in map_arry)
            {
                Console.WriteLine(map.count_island());
            }
        }
    }

    class See_map
    {
        int[,] map_arry = new int[12, 12];
        int count_temp=0,count=0;
        public See_map(List<string> map_temp)
        {
            count_temp = 0;
            foreach(string s in map_temp)
            {
                for(var i=0;i<12;i++)
                {
                    map_arry[count_temp,i]=int.Parse(s.Substring(i,1));
                }
                count_temp++;
            }
        }

        public void draw_map()
        {
            for (var i = 0; i < 12; i++)
            {
                for (var j = 0; j < 12; j++)
                {
                    Console.Write(map_arry[i,j] == 1 ? "???":"???");
                }
                Console.WriteLine();
            }
        }

        public int count_island()
        {
            for(var i=0;i<12;i++)
            {
                for(var j=0;j<12;j++)
                {
                    if (map_arry[i, j] == 1)
                    {   
                        delet_island(i, j);
                        count++;
                    }
                }
            }
            return count;
        }

        void delet_island(int x,int y)
        {
            map_arry[x, y] = 0;
            
            if(x<11)
                if (map_arry[x + 1, y] == 1) delet_island(x + 1, y);
            
            if(x>0)
                if (map_arry[x - 1, y] == 1) delet_island(x - 1, y);
            
            if(y>0)
                if (map_arry[x, y - 1] == 1) delet_island(x, y - 1);

            if(y<11)
                if (map_arry[x, y + 1] == 1) delet_island(x, y + 1);
        }

    }
}

Measured memory_bytes: 9188
import java.util.Scanner;
public class Main {
	 public static void main(String[] args) {
	        Scanner scn = new Scanner(System.in);
	        int n = scn.nextInt();
	        int m = scn.nextInt();
	        int l = scn.nextInt();
	        int[][] a = new int[n][m], b = new int[m][l];
	        for(int i = 0; i < n; i++) {
	            for(int j = 0; j < m; j++) {
	                a[i][j] = scn.nextInt();
	            }
	        }
	        for(int i = 0; i < m; i++) {
	            for(int j = 0; j < l; j++) {
	                b[i][j] = scn.nextInt();
	            }
	        }
	        for(int i = 0; i < n; i++) {
	            for(int j = 0; j < l; j++) {
	                long v = 0;
	                for(int k = 0; k < m; k++) {
	                    v += a[i][k] * b[k][j];
	                }
	                if(j > 0) System.out.print(" " + v);
	                else System.out.print("" + v);
	            }
	            System.out.println();
	        }
	    }
	}


Measured memory_bytes: 53564
def main():
    """
    0? <= h, w <= 100
        grid
    1 <= A, B <= 500

    2つの白く塗られたマス c1,c2が連結であるとは、
        マスc1からマスc2へ、
        上下左右に隣り合うマスへの移動を繰り返して、
        白く塗られたマスだけを通って移動できること

    白く塗られたマスの集合 S が連結成分であるとは、
        S のどの2 つのマスも連結である
        S に含まれないどの白く塗られたマスと、Sに含まれるどのマスも連結ではない
    """
    A, B = map(int, input().split())

    f(A, B)


def f(A, B):
    """
    解説pdfがないので、Twitter/動画を参考
    市松模様が浮かんでた
    白い海、黒い海をつくり
    白に黒の島を浮かべ、黒に白の島を浮かべるイメージらしい
    これに至る発想の流れの解説がない…発想力
        100*100だったので,最小領域で考えず最大領域を作ることはしたかった
        1マスは連結だった…
    """
    wh = "."
    bl = "#"

    grid = [
        list(wh * 50 + bl * 50)
        for _ in range(100)
    ]
    update(A, grid, wh, shift=50)
    update(B, grid, bl, shift=0)

    print(100, 100)
    for line in grid:
        print(*line, sep="")


def update(n, grid, mark, shift):
    rest = n - 1
    for i in range(0, 100, 2):
        for j in range(1+shift, shift+49, 2):
            if rest <= 0:
                return
            grid[i][j] = mark
            rest -= 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 4596
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long int
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl vector<long long>v(n);
#define mii unordered_map<ll,ll>
#define pb push_back
double pi = 2*acos(0.0);
//ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}

      
 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1;
       //cin>>tst;
    
       while(tst--)
       {
         ll n;
cin>>n;
if(n%1000==0)
cout<<0<<endl;
else

cout<<1000-(n%1000)<<endl;
       }
 }

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

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  
  int cnt = 0;
  int buff = b;
  while(buff){
    buff /=10;
    cnt++;
  }

  while(cnt){
    a *= 10;
    cnt--;
  }
  
  a = a + b;
  
  for(int i=1; i<a; i++){
    if(a/i==i && a%i==0){
      cout << "Yes" << endl;
      return 0;
    }
  
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define PI pair<int,int>
#define uint unsigned
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
const int N=305,mod=1000000007;
int n,m,ans,dp[N][N][N];
vector<PI> v[N];
#define add(a,b) a=a+b>=mod?a+b-mod:a+b
int main(){
	n=read(); m=read();
	for(int i=1;i<=m;i++){
		int l=read(),r=read(),x=read();
		v[r].push_back(mp(l,x));
	}
	dp[0][0][0]=1;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			for(int k=0;k<=n;k++)if(dp[i][j][k]){
				int pos=max(max(i,j),k);
				int flag=0;
				for(unsigned o=0;o<v[pos].size()&&!flag;o++){
					int s=(i>=v[pos][o].first)+(j>=v[pos][o].first)+(k>=v[pos][o].first);
					if(s!=v[pos][o].second)flag=1;
				}
				if(!flag){ 
					if(pos==n){
						add(ans,dp[i][j][k]); continue;
					}	
					add(dp[pos+1][j][k],dp[i][j][k]);
					add(dp[i][pos+1][k],dp[i][j][k]);
					add(dp[i][j][pos+1],dp[i][j][k]);
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 110848
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

ll num[100010];

int main(void){
    ll n;
    ll s=0;
    cin >> n;
    vector<ll> a;
    REP(i,n){
        ll tmp;
        cin >> tmp;
        num[tmp]++;
        s+=tmp;
    }
    ll q;
    cin >> q;
    REP(i,q){
        ll b,c;
        ll tmp=0;
        cin >> b >>c;
        s -=(b*num[b]);
        tmp = num[b];
        num[b] = 0;
        num[c] += tmp;
        s +=(c*tmp);
        cout << s << endl;
    }
    return 0;
}

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

using namespace std;

int N, K;
vector<int> WeightInfo;

bool judge(int w) {
	int curSum, floor;

	floor = 1;
	curSum = 0;
	for (int i = 0; i < N; ++i) {
		curSum += WeightInfo[i];
		if (curSum > w) {
			++floor;
			if (floor > K) {
				return false;
			}
			curSum = 0;
			--i;
		}
	}
	return true;
}

void solve() {
	int left, right, mid;

	left = 0;
	right = 1000000000;
	while (left < right) {
		mid = (left + right) / 2;
		if (judge(mid)) {
			right = mid;
		}
		else {
			left = mid + 1;
		}
	}

	cout << left << endl;
}

int main() {
	int w;

	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		cin >> w;
		WeightInfo.push_back(w);
	}
	solve();
	
	return 0;
}


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

int main(){
    int A,B,T;
    cin >> A >> B >> T;
    int co=0;
    int ka=A;
    while((T+0.5)>ka){
        co=co+B;
        ka=ka+A;
    }
    cout << co << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  i64 r,c,cnt;
  std::cin>>r>>c>>cnt;

  std::vector<std::vector<i64>> item(r+1,std::vector<i64>(c+1,0));

  rep(i,0,cnt){
    i64 ra,ca,v;
    std::cin>>ra>>ca>>v;
    item[ra][ca]=v;
  }

  std::vector<std::vector<std::array<i64,4>>> dp(r+1,std::vector<std::array<i64,4>>(c+1));

  rep(i,0,r+1)dp[i][0].fill(0);
  rep(i,0,c+1)dp[0][i].fill(0);

  rep(i,1,r+1){
    rep(j,1,c+1){
      rep(k,0,4){
        chmax(dp[i][j][k],dp[i][j-1][k]);
        if(k!=0)chmax(dp[i][j][k],dp[i][j-1][k-1]+item[i][j]);
        chmax(dp[i][j][0],dp[i-1][j][k]);
        chmax(dp[i][j][1],dp[i-1][j][k]+item[i][j]);
      }
    }
  }

  i64 ans=0;
  rep(i,0,4)chmax(ans,dp[r][c][i]);

  std::cout<<ans<<"\n";
  
  return 0;
}

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

int main() {
	int x[5];
	for (int i = 0; i < 5; i++) {
		cin >> x[i];
		if (x[i] == 0) {
			cout << i+1 << endl;
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

vector<ll> Vs[4];

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

    ll N, W;
    cin>>N>>W;
    ll W0, V0;
    cin>>W0>>V0;
    Vs[0].push_back(V0);
    for (ll n = 1; n < N; n++) {
        ll W, V;
        cin>>W>>V;
        Vs[W - W0].push_back(V);
    }
    for (ll i = 0; i < 4; i++) sort(begin(Vs[i]), end(Vs[i]), greater<>());

    ll ans = 0;
    for (ll s = 0; s <= Vs[0].size(); s++) {
        for (ll t = 0; t <= Vs[1].size(); t++) {
            for (ll u = 0; u <= Vs[2].size(); u++) {
                for (ll v = 0; v <= Vs[3].size(); v++) {
                    ll w = 0, V = 0;
                    for (ll i = 0; i < s; i++) { w += W0; V += Vs[0][i]; }
                    for (ll j = 0; j < t; j++) { w += W0+1; V += Vs[1][j]; }
                    for (ll k = 0; k < u; k++) { w += W0+2; V += Vs[2][k]; }
                    for (ll l = 0; l < v; l++) { w += W0+3; V += Vs[3][l]; }

                    if (w <= W) ans = max(ans, V);
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[8];
int main(){
	for(int i=0;i<8;i++)cin>>a[i];
	cout<<max(a[0]+a[1]+a[2]+a[3],a[4]+a[5]+a[6]+a[7])<<endl;
	return 0;
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		while (N < 1000) {
			if (N / 100 == ((N / 10) % 10) && N / 100 == N % 10) {
				System.out.println(N);
				break;
			}
			N += 1;
		}
	}
}

Measured memory_bytes: 21844
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int l[200000];
int r[200000];
int p[100000];
int q[100000];
int dp[501][501];
int main() {
  int n;
  cin >> n;
  cout << n / 3 << endl;
}


Measured memory_bytes: 256
#B - Nice Shopping 
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
X = []
Y = []
C = []
for i in range(M):
    x,y,c = map(int,input().split())
    X.append(x)
    Y.append(y)
    C.append(c)

#割引券を使う場合
pay_sale = [a[i-1]+b[j-1]-k for i,j,k in zip(X,Y,C)]
pay_ticket = min(pay_sale) 
#使わない場合
pay = min(a) + min(b)
print(min(pay,pay_ticket))

Measured memory_bytes: 33864
def bubble_sort(n, ary)

  index_last = n - 2

  while index_last >= 0

    for i in 0 .. index_last
      if ary[i][1] > ary[i + 1][1]
        ary[i], ary[i + 1] = ary[i + 1], ary[i]
      end
    end

    index_last -= 1
  end

  return ary
end

def selection_sort(n, ary)

  for i in 0 .. n - 2

    min = ary[i][1]
    min_index = i

    for j in i .. n - 1
      if min > ary[j][1]
        min = ary[j][1]
        min_index = j
      end
    end

    if ary[i][1] != ary[min_index][1]
      ary[i], ary[min_index] = ary[min_index], ary[i]
    end
  end

  return ary
end

def stable? (ary, org)

  (ary.size - 1).times do |i|
    if ary[i][1] == ary[i+1][1]
      if org.index(ary[i]) > org.index(ary[i+1])
        return "Not stable"
      end
    end
  end

  return "Stable"
end

num = gets.to_i
ary_original = gets.split
aryB = Marshal.load(Marshal.dump(ary_original)) #aryB: array for Bubble Sort
aryS = Marshal.load(Marshal.dump(ary_original)) #aryS: array for Selection Sort

puts bubble_sort(num, aryB).join(" "), stable?(aryB, ary_original)
puts selection_sort(num, aryS).join(" "), stable?(aryS, ary_original)



Measured memory_bytes: 6904
n,q = map(int,input().split())
s=input()
c=0
AC=[0]*(n)
for i in range(n):
    if s[i-1]=='A' and s[i]=='C':
        c+=1
    AC[i]=c


for i in range(q):
    l,r=map(int,input().split())
    print(AC[r-1]-AC[l-1])


Measured memory_bytes: 50904
n=int(input())
h=list(map(int,input().split()))
dp=[10**6]*n
dp[0]=0
dp[1]=dp[0]+abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min((dp[i-1]+abs(h[i]-h[i-1])),(dp[i-2]+abs(h[i]-h[i-2])))
print(dp[n-1])


Measured memory_bytes: 13908
while True:
  a, op, b = input().split()
  a = int(a)
  b = int(b)

  if op == '+' :
    c = a + b
    print(c)
  elif op == '-' :
    c = a - b
    print(c)
  elif op == '*' :
    c = a * b
    print(c)
  elif op == '/' :
    c = a // b
    print(c)
  if op == '?' :
    break


Measured memory_bytes: 5592
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

// https://atcoder.jp/contests/abc093/tasks/abc093_b?lang=ja

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    set<int> st;

    for (int i = A; i <= A+K-1; i++) {
        if (i > B) break;
        st.insert(i);
    }
    for (int i = B; i >= B-(K-1); i--) {
        if (i < A) break;
        st.insert(i);
    }

    for (int t : st) {
        cout << t << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Set<String> set = new HashSet<String>();
		String s = sc.next();
		int K = sc.nextInt();
		List<String> list = new ArrayList<String>();
		for (int i=0;i<s.length();i++) {
			for (int j=0;j+i<s.length()&&j<K;j++) {
				if (!set.contains(s.substring(i, i+j+1))) {
					set.add(s.substring(i, i+j+1));
					list.add(s.substring(i, i+j+1));
				}
			}
		}
		Collections.sort(list);
		System.out.println(list.get(K-1));
	}
}

Measured memory_bytes: 40980
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
const int N=300010;
map<int,int> mp;
int A[N];int B[N];
int id[N];
int tr[N<<2];
void pushup(int u){
    tr[u]=max(tr[u<<1],tr[u<<1|1]);
}
void update(int l,int r,int a,int b,int d,int u)
{
    if(l<=a&&b<=r){
        tr[u]=max(tr[u],d);
        return ;
    }
    int mid=a+b>>1;
    if(l<=mid)update(l,r,a,mid,d,u<<1);
    if(r>mid)update(l,r,mid+1,b,d,u<<1|1);
    pushup(u);
}
int query(int l,int r,int a,int b,int u){
    if(l<=a&&b<=r){
        return tr[u];
    }
    int mid=a+b>>1;
    int maxv=0;
    if(l<=mid)maxv=max(maxv,query(l,r,a,mid,u<<1));
    if(r>mid)maxv=max(maxv,query(l,r,mid+1,b,u<<1|1));
    return maxv;
}
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;++i){
        cin>>A[i];
        B[i]=A[i];
    }
    sort(B+1,B+n+1);
    int tot=1;
    for(int i=2;i<=n;++i){
        if(B[tot]!=B[i])B[++tot]=B[i];
    }
    int num=0;
    for(int i=1;i<=tot;++i)mp[B[i]]=++num;
    for(int i=1;i<=n;++i){
        id[i]=mp[A[i]];
    }
    for(int i=1;i<=n;++i){
        int tl=A[i]-k,ttr=A[i]+k;
        int kl,kr;
        int l=1,r=tot;
        while(l<r){
            int mid=l+r>>1;
            if(B[mid]>=tl)r=mid;
            else l=mid+1;
        }
        kl=l;
        l=1,r=tot;
        while(l<r){
            int mid=l+r+1>>1;
            if(B[mid]<=ttr)l=mid;
            else r=mid-1;
        }
        kr=l;
        int maxv=query(kl,kr,1,tot,1);
        update(id[i],id[i],1,tot,maxv+1,1);
    }
    cout<<tr[1]<<endl;
//    system("pause");
}

Measured memory_bytes: 18068