akhauriyash/Code-Regression huggingface dataset:
# Treap
#平衡二分木　乱数を用いてできるだけ平衡を保つらしい　
#priorityには乱数を入れること
# d = 0: right rotation
# d = 1: left rotation
def rotate(nd, d):
    c = nd[d]
    if d:
        e = c[1]
        nd[1] = c[0]
        c[0] = nd
    else:
        e = c[0]
        nd[0] = c[1]
        c[1] = nd

    r = c[4] = nd[4]
    nd[4] = r - (e[4] if e else 0) - 1
    return c

# insert a node with key = val and priority = pri
root = None
def insert(val, pri):
    global root
    st = []
    dr = []
    x = root
    while x:
        st.append(x)
        if x[2] == val:
            return
        d = (x[2] < val)
        dr.append(d)
        x = x[d]

    # [<left>, <right>, <key>, <priority>, <count>]
    nd = [None, None, val, pri, 1]
    while st:
        x = st.pop(); d = dr.pop()
        x[d] = nd
        x[4] += 1
        if x[3] >= nd[3]:
            break
        rotate(x, d)
    else:
        root = nd

    for x in st:
        x[4] += 1

def __delete(nd):
    st = []; dr = []
    while nd[0] or nd[1]:
        l = nd[0]; r = nd[1]
        d = (l[3] <= r[3]) if l and r else (l is None)
        st.append(rotate(nd, d))
        dr.append(d ^ 1)
    nd = x = None
    while st:
        nd = x; x = st.pop(); d = dr.pop()
        x[d] = nd
        x[4] -= 1
    return x

def delete(val):
    global root
    x = root

    st = []
    y = None
    while x:
        if val == x[2]:
            break
        y = x; d = (x[2] < val)
        st.append(y)
        x = x[d]
    else:
        return

    if y:
        y[d] = __delete(x)
        for x in st:
            x[4] -= 1
    else:
        root = __delete(x)

def find(val):
    global root
    x = root
    while x:
        if val == x[2]:
            return 1
        x = x[x[2] < val]
    return 0

import random

def small(val):
    global root
    x=root
    ans=0
    while x:
        if x[2]>val:
            x=x[0]
        elif x[2]<val:
            if x[0]:
                ans+=x[0][4]+1
            else:
                ans+=1
            x=x[1]
    return ans

import random,sys

input=sys.stdin.readline

N,K=map(int,input().split())
A=[]
for i in range(0,N):
    a=int(input())-K
    A.append(a)

for i in range(1,N):
    A[i]+=A[i-1]

A=[0]+A
A=[(A[i],i) for i in range(0,N+1)]
A.sort()
A=[A[i][1] for i in range(0,N+1)]
ans=0
for i in range(0,N+1):
    ans+=small(A[i])
    insert(A[i],random.randint(0,100000))

print(ans)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> link(N);
  
  for(int i=0; i<N; i++) cin >> link.at(i);

  sort(link.begin(), link.end());
  reverse(link.begin(),link.end());
  
  int L = 0;
  for(int i=0; i<K; i++) {
    L += link.at(i);
  }
  cout << L << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	string N;
	cin >> N;

	string ans = "111";

	for (int i = 1; i <= 9; i++) {
		if (N[0] <= i + '0') {
			if (N[1] <= i + '0' && N[2] <= i + '0') {
				ans[0] = i + '0';
				ans[1] = i + '0';
				ans[2] = i + '0';
			}
			else {
				ans[0] = i + '0' + 1;
				ans[1] = i + '0' + 1;
				ans[2] = i + '0' + 1;
			}
			break;
		}
	}

	cout << ans << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long int Min(long long int a, long long int b) {
	if (a < b)return a;
	else return b;
}

int main(void)
{
	long long int s, c,ans;
	scanf("%lld %lld", &s, &c);
	ans = Min(s, c / 2);
	c -= ans * 2;
	if (c >= 4) {
		ans += c / 4;
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 128
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [r,d,x2000] <- map (read::String->Int) . words <$> getLine
  (putStrLn 
    . unlines
    . map show
    . take 10
    . iterate (algae r d)
    . algae r d) x2000

algae r d x = r*x-d

Measured memory_bytes: 3920
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.IO;

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

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var n = cin.ReadInt;
            var q = cin.ReadInt;
            var s = cin.Read;
            var counts = new List<int>();
            counts.Add(0);
            var sumval = 0;

            for (var i = 0; i < s.Length-1; i++) {
                if (s[i].ToString() == "A" && s[i+1].ToString() == "C") {
                    sumval++;
                } 
                counts.Add(sumval);
            }
            
            for (var i = 0; i < q; i++) {
                var l = cin.ReadInt;
                var r = cin.ReadInt;
                var ans = counts[r-1]-counts[l-1];
                WriteLine(ans);
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 17660
#include<iostream>
using namespace std;
int main() {
	long long A,B;
	cin >> A >> B;
	long long a=4-A%4, b=B%4, n=0;
	for(long long i=A;   i<A+a; i++) n=n^i;
	for(long long i=B-b; i<=B;  i++) n=n^i;
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
lmax = -1
rmin = n+1
for i in range(m):
    l,r = inm()
    lmax = max(lmax, l)
    rmin = min(rmin, r)
print((rmin-lmax+1) if rmin >= lmax else 0)


Measured memory_bytes: 46824
#include <iostream>
#include <vector>

int main()
{
	int X, N;
	std::cin >> X >> N;
	std::vector<int> p(N);
	for (int i = 0; i < N; i++)
	{
		std::cin >> p[i];
	}

	bool flip = false, loop = true;
	int num = 0, ans=X;
	while (N != 0 && loop)
	{
		num *= -1;
		if (flip)
		{
			num -= 1;
		}
		loop = false;
		ans = X + num;
		for (int x : p)
		{
			if (x == ans)
			{
				loop = true;
				break;
			}
		}
		flip = !flip;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll      long long  
#define ld      long double
#define pii     pair<int ,int>
#define pld     pair<ld ,ld>
#define all(v)  v.begin(),v.end()
#define F       first
#define S       second
#define mod     998244353
#define pb      push_back
#define MP      make_pair
#define mset(x) memset(x, 0, sizeof(x));
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf     100000000000000
const int N=200005;

void run(){
	ll ans=0,i;
	string a,b;
	cin>>a>>b;
	for(i=0;i<3;i++)
	if(a[i]==b[i])
	ans++;
	cout<<ans;	

	

}
 
 
void setup(){
    ios;
    cout << setprecision(20);
    // #ifndef ONLINE_JUDGE
    // freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    // #endif
}
 
signed main(){
    setup();
    int tests = 1;
    //cin >> tests;
    for(int i = 1; i <= tests; i++) run();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int i, T, len, j, number, arr[52], arr_copy[52];
    number=0;
    scanf("%d", &T);
    for (i=0; i<T; i++) {
        scanf("%d", &arr[i]);
        arr_copy[i]=arr[i];
    }
    sort(arr, arr+T);
    for (j=0; j<T; j++) {
        if (arr[j] != arr_copy[j]) {
            number++;
        }
    }
    if(number==2 || number==0) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
import math
import fractions

A, B, C, D = map(int, input().split())
E = (C * D) // fractions.gcd(C, D)
count_div = 0
 
n = (A-1) // C
m = B // C
count_div += m - n

l = (A-1) // D
k = B // D
count_div += k - l

j = (A-1) // E
i = B // E
count_div -= i - j

print(B - A + 1 - count_div)

Measured memory_bytes: 65388
import sys
input = sys.stdin.readline

h, n = [int(i) for i in input().split()]
magic = [0] * n
for i in range(n):
    magic[i] = [int(i) for i in input().split()]

BIG = 10 ** 9
memo = [BIG] * (h+1)

def solve(remain_hp):
    if memo[remain_hp] != BIG:
        return memo[remain_hp]

    _min = BIG
    for m in magic:
        if remain_hp - m[0] <= 0:
            _min = min(_min, m[1])
        else:
            _min = min(_min, solve(remain_hp - m[0]) + m[1])
    memo[remain_hp] = _min
    return memo[remain_hp]

for i in range(1, h+1):
    solve(i)

print(memo[h])


Measured memory_bytes: 41200
#include<iostream>
#include<complex>
#include<cmath>
#include<map>
#define fs first
#define sc second
#define EPS (1e-10)
using namespace std;


typedef complex<double> P;
typedef pair<P,double> C;

int cpr(C a,C b){
  double d = abs(a.fs-b.fs);
  if(a.sc+b.sc + EPS < d)return -1;      //no intersection (outside)
  if(b.sc+d + EPS < a.sc)return 1;       //no intersection (inside,B in A)
  if(a.sc+d + EPS < b.sc)return 2;       //no intersection (inside,A in B)
  if(abs(a.sc+b.sc - d) < EPS)return -3; //one cross point (outside)
  if(abs(b.sc+d - a.sc) < EPS)return 3;  //one cross point (inside,B in A)
  if(abs(a.sc+d - b.sc) < EPS)return 4;  //one cross point (inside,A in B)
  return 0;                              //two cross point
}


int main(){
  double ax,ay,ar,bx,by,br;

  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin>> ax >> ay >> ar >> bx >> by >> br;
    C a = C(P(ax,ay),ar), b = C(P(bx,by),br);
    int v = cpr(a,b);
    if(v==-1)cout <<  0 << endl;
    else if(v==1)cout << 2 << endl;
    else if(v==2)cout << -2 << endl;
    else cout << 1 << endl;
  }
}

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

const int N = 4005, M = 1e9+7;
int dp[N][N];
int dp2[N][N];

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

    int o, z, k;
    cin>>o>>z>>k;

    int n = (o+z-1)/(k-1);

    dp[0][0] = 1;

    for (int i=1; i<=n; i++) {
        int prsum = (i-1)*(k-1);
        for (int pz=0; pz<=prsum; pz++) {
            int po = prsum-pz;
            for (int cz=0; cz<k; cz++) {
                int co = k-1-cz;
                dp[pz+cz][po+co] = (dp[pz+cz][po+co] + dp[pz][po])%M;
                if (co) dp2[pz+cz][po+co] = (dp2[pz+cz][po+co] + dp[pz][po])%M;
            }
        }
    }

    int ans = 0;
    for (int i=z-1; i>=0; i-=k-1) {
        for (int j=o; j>0; j-=k-1) {
            ans = (ans + dp2[i][j])%M;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 93860
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a+b==15)
	cout<<"+"<<endl;
	if(a*b==15)
	cout<<"*"<<endl;
	if(a+b!=15&&a*b!=15)
	cout<<"x";
} 

Measured memory_bytes: 256
import Data.Char
import Data.List
import Data.Maybe

main :: IO ()
main = do
    s <- map digitToInt
         . filter (not . isSpace) <$> getLine :: IO [Int]
    k <- readLn :: IO Int
    print $ if all (==1) $ take k s
               then 1 else fromJust $ find (/=1) s


Measured memory_bytes: 508
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;






int main(){


        int n,x;
        cin >> n >> x; 

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

        int tmp = 0;
        int cnt = 1;
        for(int i = 0; i < n; i++){
                tmp += l[i];
                if(tmp > x) break;
                cnt++;
        }


        cout << cnt << endl;

        return 0;

}



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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n,k;
  cin >> n >> k;
  vector<vector<LL>> c(2001,vector<LL>(2001));
  rep(i,2001){
    c[i][0]=1,c[i][i]=1;
    repp(j,1,i){
      c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;
    }
  }
  repp(i,1,k+1){
    if(k-i<0||n-k-(i-1)<0) cout << 0 << endl;
    else cout << c[k-1][i-1]*c[n-k+1][i]%MOD << endl;
  }
  return 0;
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

struct Trie {
    vector<Trie*> to;
    Trie* par;
    vector<int> cntchar;
    Trie() {
        to.resize(26, NULL);
        par = NULL;
        cntchar.resize(26,0);
    }
};

void solve() {
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i, n) {
        cin >> s[i];
    }
    Trie* root = new Trie();
    vector<Trie*> gchild(n, NULL);
    REP(i, n) {
        string& nowst = s[i];
        Trie* nownode = root;
        IREP(j, nowst.size()) {
            int now = nowst[j] - 'a';
            if (nownode->to[now] == NULL) {
                Trie* nextnode = new Trie();
                nownode->to[now] = nextnode;
                nextnode->par = nownode;
                nownode = nextnode;
            } else {
                nownode = nownode->to[now];
            }
        }
        gchild[i] = nownode;
        vector<bool> memo(26, false);
        int nowidx = 0;
        while (nownode != root) {
            int now = nowst[nowidx++] - 'a';
            memo[now] = true;
            nownode = nownode->par;
            if (nownode != NULL) {
                REP(k, 26) {
                    if (memo[k]) {
                        ++(nownode->cntchar[k]);
                    }
                }
            }
        }
    }

    ll ans = 0;
    REP(i,n) {
        Trie* now = gchild[i];
        int cnt = 0;
        if (now->par != NULL) {
            int nowidx = s[i][cnt] - 'a';
            Trie* parnode = now->par;
            ans += parnode->cntchar[nowidx] - 1;
            now = now->par;
        }
    }
    cout << ans << endl;
}

int main() {
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



Measured memory_bytes: 395068
import java.util.Scanner;

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

        int n = scanner.nextInt();
        int oddCount;
        if (n % 2 == 0)
            oddCount = n / 2;
        else
            oddCount = (n + 1) / 2;

        System.out.println((float) oddCount / n);
    }
}


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

#define REP(i, a, b) for(i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

using namespace std;

int main(){
    int i, count = 0;
    char str[5], myans[5] = "aa";
    char st, ed;
    char used[100][5];

    memset(used, -1, sizeof(used));

    while(true){
        printf("?%s\n", myans); fflush(stdout);
        scanf("%s", str);
        
        //ツ鳴鳴氾カツづ静ヲツ督ェツチツェツッツク
        for(i = 0; myans[i] != '\0'; i++);
        ed = myans[i-1], st = str[0];
        
        if(ed != st){
            cout << "!OUT" << endl;
            return 0;
        }

        //ツつキツづづ可使ツづつスツ単ツ古ェツつゥツチツェツッツク
        rep(i, 100){
            if(strcmp(str, used[i]) == 0){
                cout << "!OUT" << endl;
                return 0;
            }
        }
        strcpy(used[count], myans);
        count++;
        strcpy(used[count], str);
        
        //50ツタツーツδ督づ可達ツつオツつス
        if(count >= 100) cout << "!OUT" << endl;
        
        for(i = 0; str[i] != '\0'; i++);
        myans[0] = str[i-1];
        myans[1] = str[i-1];
        myans[2] = 'a';
        myans[3] = '\0';

        if(strcmp(str, "a") == 0){
            myans[0] = 'a';
            myans[1] = 'b';
            myans[2] = 'a';
            myans[3] = '\0';
        }
        count++;
    }
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Collections.reverseOrder());
    int n = sc.nextInt();
    int m = sc.nextInt();
    ArrayList[] list = new ArrayList[m + 1];
    for(int i = 0; i < m + 1; i++) {
      list[i] = new ArrayList<Integer>();
    }
    for(int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(a < (m + 1)) list[a].add(b);
    }
    int ans = 0;
    for(int i = 1; i <= m; i++) {
      for(int j = 0; j < list[i].size(); j++) {
        pq.add((int)(list[i].get(j))); 
      }
      if(pq.size() > 0) ans += pq.poll();
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 102440
import std.stdio, std.string, std.conv, std.algorithm;

void main(){
	int n;
	while(n=readln.chomp.to!int,n){
		int cnt;
		foreach(i;1..n){
			int sum;
			foreach(j;i..n){
				sum += j;
				if(sum==n){
					cnt++;
					break;
				}
				if(sum>n) break;
			}
		}
		cnt.writeln;
	}
}

Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    float d,t,s;
    cin>>d>>t>>s;
    if(d/s <= t)
    {
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
    return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

ll f(vector<ll> &A,ll b) {
  ll c = 0;
  rep(i,(int)A.size()) {
    c += llabs(A[i]-(b+(ll)i+1LL));
  }
  return c;
}
ll ternarySearch(vector<ll> &A){
  ll L = -10000000000LL, R = 10000000000LL;

  rep(_,120){
    if( f(A,((L+R*2)/3)) > f(A,((L*2+R)/3)) ) {
      R = ( L + R * 2 ) / 3LL;
    } else {
      L = ( L * 2 + R ) / 3LL;
    }
  }
  //return heron(nps[(int)(((L+R)*0.5)+sp)%nV],nps[a],nps[b]);
  return f(A,(((L+R)/2LL)));
}

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  rep(i,n) cin >> A[i];
  cout << ternarySearch(A) << endl;
  for(int b=-10;b<=10;++b) {
    //cout<< b << " : " << calc(A,b) << endl;
  }
  compute();
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define OK { cout << "OK" << endl; return 0; }
#define NG { cout << "NG" << endl; return 0; }
#define sz(v) ((int)(v).size())
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void out(T a){cout << a << endl;}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

#define SIZE 200005
#define MOD 1000000007
 
typedef pair <int,int> P;
 
ll inv[SIZE], fac[SIZE], finv[SIZE];
void make(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<SIZE; i++)
	{
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
    return ;
}
ll comb(int a,int b){
	if(a < b) return 0;
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}



ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
	int N; cin >> N;
    vl A(N); vin(A);

    sort(rall(A));
    //dab(A);
    //ll ans = A[0];
    ll ans = 0;
    int counter = 1;
    rep(i,N-1) {
        ans += A[counter/2];
       // cout << A[counter/2] << endl;
        counter++;
    }
    cout << ans << endl;


}

Measured memory_bytes: 4772
from collections import deque
N = int(input())
used1 = [0] * N
used2 = [0] * N

ans_list = [0] * 500
for i in range(1, 500):
  ans_list[i] = int(i * (i + 1) // 2)

if N in ans_list:
  print("Yes")
  k = ans_list.index(N)
  print(k + 1)
  A = [deque([]) for i in range(k)]
  for i in range(1, N + 1):#最大10 ** 5
    p = int(((1 + 8 * i) ** (1/ 2) - 1.001) // 2)
    A[p].append(i)
  #print(A)
  #print(A[1][0])
  for i in range(k):
    print(k, end = " ")
    for j in range(i + 1):
      #print("j", j)
      print(A[i][j], end = " ")
    for l in range(i + 1, k):
      print(A[l][i], end = " ")
    print("")
  
  print(k, end = " ")
  for i in range(k):
    print(A[i][i], end = " ")
  print("")
else:
  print("No")

Measured memory_bytes: 56920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using Graph = vector<vector<int>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> A(9,0);
    vector<bool> Abool(9,false);
    rep(i,9) cin >> A.at(i);
    int N;
    bool ans = false;
    cin >> N;
    rep(i,N) {
        int b;
        cin >> b;
        rep(j,9) {
            if(A.at(j)==b) {
                Abool.at(j) = true;
            }
        }
    }
    if (Abool.at(0)&Abool.at(1)&Abool.at(2)) {
        ans = true;
    }
    else if (Abool.at(3)&Abool.at(4)&Abool.at(5)) {
        ans = true;
    }
    else if (Abool.at(6)&Abool.at(7)&Abool.at(8)) {
        ans = true;
    }
    else if (Abool.at(0)&Abool.at(3)&Abool.at(6)) {
        ans = true;
    }
    else if (Abool.at(1)&Abool.at(4)&Abool.at(7)) {
        ans = true;
    }
    else if (Abool.at(2)&Abool.at(5)&Abool.at(8)) {
        ans = true;
    }
    else if (Abool.at(0)&Abool.at(4)&Abool.at(8)) {
        ans = true;
    }
    else if (Abool.at(2)&Abool.at(4)&Abool.at(6)) {
        ans = true;
    }
    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  string a = "No";
  if(A == B && B != C) {
    a = "Yes";
  }
  if(C == B && B != A) {
    a = "Yes";
  }
  if(A == C && A != B) {
    a = "Yes";
  }
  cout << a << endl;
}

Measured memory_bytes: 256
n,m,x,y = map(int,input().split())

xis = sorted(list(map(int,input().split())),reverse=True)
yis = sorted(list(map(int,input().split())))
 
ans = 'No War' if (xis[0] < yis[0]) and (x < yis[0] and xis[0] < y) else 'War'

print(ans)


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

int main(void) {
  int i, j;
  int tmp, a[3], b[3];
  vector<int> c;
  bool flag;

  // stdin
  for (i=0; i<3; i++) {
    for (j=0; j<3; j++) {
      cin >> tmp;
      c.push_back(tmp);
    }
  }

  // calculate
  flag = 1;
  for (i=0; i<3; i++) {
    // set a0
    a[0] = i; 

    // solv b
    for (j=0; j<3; j++) {
      b[j] = c[j] - a[0];
    }

    // solv a
    for (j=1; j<3; j++) {
      a[j] = c[3*j] - b[0];
    }
    
    // solv
    for (i=1; i<3; i++) {
      for (j=1; j<3; j++) {
        if (c[3*i + j] != a[i] + b[j]) {
          flag = 0;
          break;
        }
      }
    }
  }

  // stdout
  cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

A.sort()

if N % 2 == 1:
    check = [0]
    for i in range(2, N + 1, 2):
        check.append(i)
        check.append(i)
    if A != check:
        print(0)
        exit(0)
else:
    check = []
    for i in range(1, N + 1, 2):
        check.append(i)
        check.append(i)
    if A != check:
        print(0)
        exit(0)

ans = 1
for _ in range(N // 2):
    ans *= 2
    ans %= MOD

print(ans)

Measured memory_bytes: 14008
#N人　K種類のお菓子
[N, K] = [int(i) for i in input().split()]

okasi = [0]*N #i番目の人が持っているお菓子の中で、種類番号が多いものに更新する

#お菓子K種類渡す
for k in range(K):
    num = int(input()) #お菓子の番号
    have = [int(i) for i in input().split()]
    for snuke in have:
        okasi[snuke-1] = num

#お菓子持ってない人を探す
print(okasi.count(0))

Measured memory_bytes: 9196
#ifdef loc
    #include "codes/loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 100005;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, d;
    cin >> n >> d;
    int res = 1;
    int nx = 2 * d + 2;
    while(nx <= n) {
        res++;
        nx += 2 * d + 1;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
a = []
3.times do
  a << gets.split.map(&:to_i)
end
a.flatten!
bingos = [
  a[0..2],
  a[3..5],
  a[6..8],
  [a[0], a[3], a[6]],
  [a[1], a[4], a[7]],
  [a[2], a[5], a[8]],
  [a[0], a[4], a[8]],
  [a[2], a[4], a[6]],
]
n = gets.to_i
nums = []
n.times do
  nums << gets.to_i
end
bingos.each do |b|
  if (b - nums).empty?
    puts 'Yes'
    exit 0
  end
end
puts 'No'

Measured memory_bytes: 1916
//#define sort(nums) sort(nums.begin(),nums.end())
#include <bits/stdc++.h>
#define mod 1000000007
#define deb(x) cout<<#x<<" "<<x<<endl
using namespace std;
using ll = long long int;

void jets(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


int main(){
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    jets();
    int n;
    cin>>n;
    int mat[n][3];
    for(int i=0;i<n;i++){
    	for(int j=0;j<3;j++)
    		cin>>mat[i][j];
    }
    int dp[n][3];
    memset(dp,0,sizeof(dp));
    dp[0][0]=mat[0][0];
    dp[0][1]=mat[0][1];
    dp[0][2]=mat[0][2];
    for(int i=1;i<n;i++){
    	dp[i][0]=mat[i][0]+max(dp[i-1][1],dp[i-1][2]);
    	dp[i][1]=mat[i][1]+max(dp[i-1][0],dp[i-1][2]);
    	dp[i][2]=mat[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;


    return 0;
}

Measured memory_bytes: 5916
#include <iostream>
#include <string>

using namespace std;
 
int main() {
	int a,b,c;
	cin >>a>>b>>c;
	int max=a;
	if(b>max){
		max = b;
	}
	if(c>max){
		max = c;
	}
	cout << a+b+c-max << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main(void){
	char cha1[1000], cha2[1000], a[1000];
	cin >> cha1;
	cin >> a;
	strcpy(cha2, cha1);
	strcat(cha1, cha2);
	if (strstr(cha1, a) != NULL){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

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

int main(void)
{
    
    int n;
    cin >> n;
    vector<int> in(n);
    for (int i = 0; i < n; i++) cin >> in[i];

    bool buy = true;
    long long money = 1000;
    long long stock = 0;
    bool stopBuying = false;
    for (int i = 0; i < n;)
    {
        int j;
        for (j = i; j < n; j++)
        {
            if (j == n - 1)
            {
                if (buy) stopBuying = true;
                break;
            }
            else
            {
                if (buy && in[j] < in[j + 1]) break;
                if (!buy && in[j] > in[j + 1]) break;
            }
        }

        if (stopBuying) break;

        long long targetValue = in[j];
        if (buy)
        {
            stock = money / targetValue;
            money %= targetValue;
        }
        else
        {
            money = money + stock * targetValue;
            stock = 0;
        }

        buy = !buy;
        i = j+1;
    }

    cout << money << endl;

    return 0;
}

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

struct C {
  public:
    string s;
    int n;
    int p;

    C(string s, int n, int p) : s(s), n(n), p(p) {};

    bool operator<(const C &c) const {
      if (this->n < c.n) {
        return true;
      }
      return false;
    }
};

template<typename T>
int partition(vector<T> &a, int p, int r) {
  T x = a[r - 1];
  int i = p;
  for (int j = p; j < r - 1; ++j) {
    if (!(x < a[j])) {
      T t = a[i];
      a[i] = a[j];
      a[j] = t;
      ++i;
    }
  }
  T t = a[i];
  a[i] = a[r - 1];
  a[r - 1] = t;
  return i;
}

template<typename T>
void quick_sort(vector<T> &a, int p, int r) {
  if (p < r - 1) {
    int q = partition(a, p, r);
    quick_sort(a, p, q);
    quick_sort(a, q + 1, r);
  }
}

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

  int n;
  cin >> n;
  vector<C> a;
  for (int i = 0; i < n; ++i) {
    string s;
    int t;
    cin >> s >> t;
    a.push_back(C(s, t, i));
  }

  quick_sort(a, 0, n);
  bool stable = true;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i].n != a[i + 1].n) {
      continue;
    }
    if (a[i].p > a[i + 1].p) {
      stable = false;
    }
  }

  cout << (stable ? "Stable" : "Not stable") << endl;
  for (int i = 0; i < n; ++i) {
    cout << a[i].s << " " << a[i].n << endl;
  }

  return 0;
}



Measured memory_bytes: 8988
import java.util.*;
public class Main
{
    public static long findGCD(long c,long d)
    {
        if (d != 0)
       return findGCD(d, c%d);
    else 
       return c;
    }
  public static void main(String[] args)
  {
    Scanner Sc=new Scanner(System.in);
    long a=Sc.nextLong();
    long b=Sc.nextLong();
    long c=Sc.nextInt();
    long d=Sc.nextInt();
    long g=findGCD(c,d);
    long l=(c*d)/g;
    long mc=(b/c)-((a-1)/c);
    long md=(b/d)-((a-1)/d);
    long ml=(b/l)-((a-1)/l);
    System.out.println((b-a+1)-(mc+md)+ml);
  }
}


Measured memory_bytes: 21972
// AOJ 2840: Unique Subsequence
// 2017.10.10 bal4u@uu

#include <stdio.h>

char text[500005];
char pattern[500005];

int main()
{
	int f;
	char *p, *q;

	scanf("%s%s", text, pattern+1);
	p = text, q = pattern+1, f = 0;
	while (*p) {
		if (*p == *q) {	q++; if (!*q) f = 1; }
		else if (*p == *(q-1)) { f = 0; break; }
		p++;
	}
	puts(f ? "yes" : "no");
	return 0;
}

Measured memory_bytes: 2604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class93
    {
        static void Main()
        {
            var abck = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long a = abck[0], b = abck[1], c = abck[2], k = abck[3];
            long ans = 0;
            if (k % 2 == 0)
            {
                ans = a - b;
            }
            else
            {
                ans = b - a;
            }
            Console.WriteLine(ans);
        }
    }
}


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

int main(){
  int n, y, sum;

  cin >> n >> y;

  sum = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n - i; j++) {
      int k = n - i - j;
      sum = 10000*i + 5000*j + 1000*k;
      if (sum == y) {
        printf("%d %d %d\n", i, j, k);
        return 0;
      }
    }
  }

  printf("-1 -1 -1\n");

  return 0;
}

Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    // https://atcoder.jp/contests/abc147/submissions/8921445
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        A : i32,
        B : i32,
    );

    println!("{}", 6 - A - B);
}

Measured memory_bytes: 4352
def ten_mod(x):
    ans = 10 if (x%10)==0 else x%10
    return ans

x = int(input())
ans = x if (x%10)==0 else int(x/10)*10+10
last = x

for i in range(5-1):
    x = int(input())
    ans += x if (x%10)==0 else int(x/10)*10+10
    if ten_mod(last) > ten_mod(x):
        last = x

ans = ans - 10 + (last%10) if (last%10) != 0 else ans
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}



int main(){
  ll n,w ; cin>>n>>w ;
  vector<ll> A(n) , B(n) ;
  rep(i,n){
      cin>> A[i]>>B[i] ;
  }
  ll p = A[0] ;
  vector<ll> a,b,c,d ;
  rep(i,n){
      if(A[i]==p) a.pb(B[i]) ;
      if(A[i]==p+1) b.pb(B[i]) ;
      if(A[i]==p+2) c.pb(B[i]) ;
      if(A[i]==p+3) d.pb(B[i]) ;
  }
  sort(a.rbegin(),a.rend()) ;
  sort(b.rbegin(),b.rend()) ;
  sort(c.rbegin(),c.rend()) ;
  sort(d.rbegin(),d.rend()) ;
  ll asize = a.size() ;
  ll bsize = b.size() ;
  ll csize= c.size() ;
  ll dsize = d.size() ;
  ll ans = 0 ;
  vector<ll> asum(asize+1) ,bsum(bsize+1) ,csum(csize+1),dsum(dsize+1) ;
  rep(i,asize) asum[i+1] = asum[i]+a[i] ;
  rep(i,bsize) bsum[i+1]= bsum[i]+b[i] ;
  rep(i,csize) csum[i+1]=csum[i]+c[i] ;
  rep(i,dsize) dsum[i+1]= dsum[i]+ d[i] ;
  rep(pp,asize+1){
      rep(q,bsize+1){
          rep(r,csize+1){
              rep(s,dsize+1){
                  if(w>=(pp*p+q*(p+1)+r*(p+2)+s*(p+3)))
                  chmax(ans,asum[pp]+bsum[q]+csum[r]+dsum[s]) ;
              }
          }
      }
  }
  cout<<ans<<endl;
   return 0 ; 
}



Measured memory_bytes: 3548
#include <stdio.h>

int main(void) {
	signed int n, a, b, c, d, i, j, arr[13][11]={0};
	

	scanf("%d", &n);
	
	for(i=0;i<n;i++){
		scanf("%d %d %d %d", &a, &b, &c, &d);
		arr[(a-1)*3+b][c]+=d;
	}
	
	for(i=1;i<=12;i++){

		
		for(j=1;j<=10;j++)
		printf(" %d", arr[i][j]);
		printf("\n");
		
		if(i%3==0 && i!=12)
printf("####################\n");
		
	}
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());
  int x = 1, total = 0;
  vector<int> cnt(2019);
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    cnt[total]++;
    total += (s[i] - '0') * x;
    total %= 2019;
    ans += cnt[total];
    x = x * 10 % 2019;
  }
  cout << ans << endl;
}

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

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

  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int m = 2500;
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    auto ndp = dp;
    for (int j = 1; j <= n; j++) {
      for (int k = x[i]; k <= m; k++) {
        ndp[j][k] += dp[j-1][k-x[i]];
      }
    }
    dp = ndp;
  }
  long long res = 0;
  for (int i = 1; i <= n; i++) res += dp[i][a*i];
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 2336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int x;
	cin >> x;
	if (x == 7 || x == 5 || x == 3) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a == b && a != c)
		cout << "Yes";
	else if (a == c && a != b)
		cout << "Yes";
	else if (b == c && b != a)
		cout << "Yes";
	else
		cout << "No";

}

Measured memory_bytes: 3520
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 998244353
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    N,K = LI()
    a = [LI() for _ in range(K)]

    m = [0] * (N+1)
    s = 1

    for i in range(1,N):
        s = (s + m[i]) % MOD
        if s:
            for l,r in a:
                if i + l <= N:
                    m[i+l] = (m[i+l] + s) % MOD
                if i + r + 1 <= N:
                    m[i+r+1] = (m[i+r+1] - s) % MOD
    print(m[-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 71868
import math
a,b,h,m=input().split(' ')
w1=2*math.pi/720.0
w2=2*math.pi/60.0
t1 = w1*(int(h)*60+int(m))
t2 = w2*int(m)
t3 = abs(t1-t2)
l3 = math.sqrt(int(a)*int(a)+int(b)*int(b)-(2*int(a)*int(b)*math.cos(t3)))
print(l3)


Measured memory_bytes: 9516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1000000007;
const ll ARR_MAX = 1e5+1;
const ll INF=1e14;

void solve(){
    int n;cin>>n;
    ll w;cin>>w;
    ll weight[n],value[n];
    for(int i=0;i<n;i++){
    	cin>>weight[i]>>value[i];
    }
    ll dp[w+1],prev[w+1]={}; //dp[j]= max value with weight as j.
    for(int j=0;j<=w;j++){
    	dp[j]=-INF;
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
    	for(int j=0;j<=w;j++){
    		prev[j]=dp[j];
    	}

    	for(int j=weight[i];j<=w;j++){
    		// prev[j]=dp[j];
    		dp[j]=max(prev[j],prev[j-weight[i]]+value[i]);
    	}
    }
    ll mx=0;
    for(int j=0;j<=w;j++){
    	mx=max(mx,dp[j]);
    }
    cout<<mx<<nl;
}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

int main() {
  int n,m,l;
  cin >> n >> m >> l;
  vector<vector<int>>a(n,vector<int>(m));
  vector<vector<int>>b(m,vector<int>(l));
  for(int i = 0;i < n;i++){
    for(int j = 0;j < m;j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0;i < m;i++){
    for(int j = 0;j < l;j++){
      cin >> b[i][j];
    }
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < l;j++){
      long c = 0;
      for(int k = 0;k < m;k++){
        c += a[i][k]*b[k][j];
      }
      cout << c;
      if(j == l-1) cout << "" << endl;
      else cout << " ";
    }
  }
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2002;
bitset<maxn * maxn> f;
int main(){
	int s = 0;
	int n; cin >> n;
	f[0] = 1;
	for(int i = 0; i < n; i++){
		int x; cin >> x;
		f = f|(f<<x);
		s += x;
	}
	s += 1;
	s /= 2;
	while(!f[s]) s++;
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 2176
#include<map>
int64_t k,t=1,n,p;int S(int64_t x){return x?x%10+S(x/10):0;}int main(){scanf("%d",&k);while(printf("%ld\n",n+=t),--k)t+=t*9*(S(p=n+t+t)*(n+t)>S(n+t)*p);}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int n,i,a[101];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=n-1;i>=0;i--){
		printf("%d",a[i]);
		if(i!=0) printf(" ");
	}
	printf("\n");
	return 0;
}
	

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int ans = 0,count = 0;
    string s;
    cin >> s;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
        {
            count++;
        }
        else
        {
            if(ans < count)
            {
                ans = count;
            }
            count = 0;
        }
    }
    if(ans < count){ans = count;}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from heapq import heappop, heappush
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
N, K = inpl()
DT = sorted([inpl()[::-1] for _ in range(N)], reverse=True)


dic = defaultdict(list)
counter = defaultdict(int)
for d, t in DT:
    dic[t].append(d)
    counter[t] += 1
each_max = {k: max(v) for k, v in dic.items()}
oic = 0

all_ = set(dic.keys())
eat = defaultdict(list)
for i in range(K):
    d, t = DT[i]
    eat[t].append(d)
    oic += d
x = len(eat)
score = oic + x*x
heap = []

for k, v in eat.items():
    if len(v) >= 2:
        heappush(heap, (min(v), k))

not_eat = sorted([max(dic[k]) for k in all_ - set(eat.keys())])
while heap:
    if len(not_eat) == 0:
        break
    v, k = heappop(heap)
    oic -= v - not_eat.pop()
    x += 1
    _ = eat[k].pop()
    if len(eat[k]) >= 2:
        heappush(heap, (min(eat[k]), k))

    score = max(score, oic + x*x)

print(score)

Measured memory_bytes: 67904