akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
using namespace std;
vector<int> t(31);
void a(){
swap(t[13],t[18]);swap(t[7],t[22]);swap(t[8],t[23]);
swap(t[9],t[24]);swap(t[10],t[12]);
}
void b(void){
swap(t[15],t[16]);swap(t[1],t[28]);swap(t[2],t[29]);swap(t[3],t[30]);swap(t[19],t[21]);
}
void c(void){
swap(t[3],t[22]);swap(t[6],t[25]);swap(t[9],t[28]);swap(t[13],t[15]);swap(t[12],t[19]);
}
void d(void){
swap(t[7],t[30]);swap(t[4],t[27]);swap(t[1],t[24]);swap(t[10],t[21]);swap(t[16],t[18]);
}
bool ok(vector<int>x){
int mae=x[1];
//for(int i=0;i<x.size();i++)cout<<i<<" "<<x[i]<<endl;
for(int i=1;i<=9;i++)if(x[i]!=mae)return false;
mae=x[10];
for(int i=10;i<=12;i++)if(x[i]!=mae)return false;
mae=x[13];
for(int i=13;i<=15;i++)if(x[i]!=mae)return false;
mae=x[16];
for(int i=16;i<=18;i++)if(x[i]!=mae)return false;
mae=x[19];
for(int i=19;i<=21;i++)if(x[i]!=mae)return false;
mae=x[22];
for(int i=22;i<=30;i++)if(x[i]!=mae)return false;
return true;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		t[0]=0;
		for(int j=1;j<=30;j++)cin>>t[j];
	queue<pair<int,vector<int> > >bfs;
	bfs.push(pair<int,vector<int> >(0,t));

	while(!bfs.empty()){
	pair<int,vector<int> >tmp=bfs.front();
	vector<int>tt(31);
	for(int k=1;k<=30;k++){tt[k]=tmp.second[k];t[k]=tmp.second[k];}
	bfs.pop();
		int tf=tmp.first;
		if(tf>9){cout<<"error"<<endl;break;}
		if(ok(tt)){
		cout<<tf<<endl;
		break;
		}
		a();
		//for(int kk=0;kk<t.size();kk++)cout<<t[kk];cout<<endl;
		bfs.push(make_pair(tf+1,t));
		for(int k=1;k<=30;k++)t[k]=tt[k];
		b();
		//for(int kk=0;kk<t.size();kk++)cout<<t[kk];cout<<endl;
		bfs.push(make_pair(tf+1,t));
		for(int k=1;k<=30;k++)t[k]=tt[k];
		c();
		//for(int kk=0;kk<t.size();kk++)cout<<t[kk];cout<<endl;
		bfs.push(make_pair(tf+1,t));
		for(int k=1;k<=30;k++)t[k]=tt[k];
		d();
		//for(int kk=0;kk<t.size();kk++)cout<<t[kk];cout<<endl;
		bfs.push(make_pair(tf+1,t));
		for(int k=1;k<=30;k++)t[k]=tt[k];
	}
}
	return 0;
}

Measured memory_bytes: 15864
s = input()

ans = 0
x = 0
index = 0

while index < len(s):
    if s[index] == 'A':
        x += 1
        index += 1
    elif s[index:index+2] == "BC":
        ans += x
        index += 2
    else:
         index += 1
         x = 0

print(ans)


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  
  char a;
  cin >> a;
  cout << char((int)a + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

vector<int> to[200005];
vector<int> ans;
void dfs(int v,int p=-1){
    for(int u : to[v]){
        if(u==p) continue;
        ans[u]+=ans[v];
        dfs(u,v);
    }
}

int main(){
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    for(int i=0;i<q;i++){
        int p,x;
        cin>>p>>x;
        p--;
        ans[p]+=x;
    }
    dfs(0);
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 23552
N = int(input())
W = [input() for i in range(N)]

wordset = set()
last= W[0][0]

for i in W:
    if last != i[0]:
        print("No")
        exit()
    else:
        wordset.add(i)
        last = i[-1]

print("Yes" if len(wordset) == N else "No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <atcoder/all>
#define F first
#define S second
using namespace std;
using namespace atcoder;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,M;
  cin >> N >> M;
  scc_graph G(N);
  for (int i = 0; i < M; i++) {
    int a,b;
    cin >> a >> b;
    G.add_edge(a,b);
  }
  vector<vector<int>> ans = G.scc();
  cout << (int)ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); i++) {
    cout << (int)ans[i].size() << " ";
    for (int j = 0; j < (int)ans[i].size(); j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 40588
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y,ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        ll w=(p*p)%z;
        if(y%2==0)
         return w;
        else
        return (x*w)%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n,a=0;
    cin>>n;
    for(int i=1;i<n;i++)
    {
       a=a+(n-1)/i;
    }
    cout<<a;}

Measured memory_bytes: 3644
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
dpa = [0]*N
dpb = [0]*N
dpc = [0]*N
dpa[0] = A[0][0]
dpb[0] = A[0][1]
dpc[0] = A[0][2]
for i in range(1,N):
    a = A[i][0]
    b = A[i][1]
    c = A[i][2]
    dpa[i] = max(dpb[i-1]+a,dpc[i-1]+a)
    dpb[i] = max(dpa[i-1]+b,dpc[i-1]+b)
    dpc[i] = max(dpb[i-1]+c,dpa[i-1]+c)
Min = dpa[N-1]
Mmin = max(dpb[N-1],dpc[N-1])
print(max(Min,Mmin))

Measured memory_bytes: 65752
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    int n;
    int cnt = 0;
    string s;

    cin >> n >> s;

    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            cnt++;
        }
    }

    if (cnt > n/2) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  	long int n;
  	long long temp, a;
  	cin>>n;
  	cin>>a;
  	long long int ans = 0;
  	for(long int i = 1; i<n; i++)
  	{
  		cin>>temp;
  		if(temp<a) ans += a-temp;

  		a = max(a,temp);
  		//cout<<ans<<" ";
  	}
  	cout<<ans;
}	

Measured memory_bytes: 3596
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

a.sort()

L = [0] * 2001

co = 0

ans = 0

for i in range(n-2):
    for j in range(i+1):
        L[a[i+1] + a[j]] += 1
    ans += sum(L[a[i+2]+1:])

print(ans)





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

vector<pair<int, int>> ans;

void solve(int N){
    for(int i=1; i<N; i++) ans.push_back({i, N});
    for(int i=1; i<N; i++) for(int j=i+1; j<N; j++){
        if(i+j != N) ans.push_back({i, j});
    }
}

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

    solve(N%2 ? N : N-1);

    if(N%2){
        cout << ans.size() << endl;
        for(auto& p : ans) cout << p.first << " " << p.second << endl;
    }else{
        for(int i=1; i<N-1; i++) ans.push_back({0, i});
        cout << ans.size() << endl;
        for(auto& p : ans) cout << p.first+1 << " " << p.second+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 998244353
#define inf -1000000000000000000
int n,k;
// vector<int>a;
int main() {
	io
	cin>>n>>k;
	set<int>s;
	while(k--) {
		int d;
		cin>>d;
		vector<int>a(d);
		for(int i = 0; i<d; i++) {
			cin>>a[i];
			s.insert(a[i]);
		}
	}
	cout<<n-s.size();
	
}


Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll, lint;
typedef long double ldouble;

#define sz(v) ((int) (v).size())
#define FOR(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define For(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

template<class T>
string to_string(T arr, int len = 1e9) {
    stringstream ss;
    int i = 0;
    for (auto item : arr) {
        ss << item << ' ';
        if (++i == len)
            break;
    }
    return ss.str();
}

#ifdef LOCAL
    #define dbg(expr) cout << "[line " << __LINE__ << "] " << (#expr) << ": " << (expr) << endl;
#else
    #define dbg(expr) (void) 0;
#endif


int main() {
#ifndef LOCAL
    cin.tie(0);
    ios_base::sync_with_stdio(false);
#endif

    int n;
    cin >> n;
    vector<lint> values(n);
    For (i, n)
        cin >> values[i];
    sort(all(values));

    lint max_val = values[0];
    for (auto e : values)
        max_val = max(e, max_val);

    lint mid = (max_val + 1) / 2;
    auto it = lower_bound(all(values), mid);
    lint best = *it;
    if (it != values.begin()) {
        lint another = *prev(it);
        if (abs(another - mid) <= abs(best - mid))
            best = another;
    }

    cout << max_val << ' ' << best << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        int[] d = new int[N];

        for (int i = 0; i < N; i++)
            d[i] = sc.nextInt();

        int sum = 0;

        for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++) {
                sum += d[i] * d[j];
            }

        System.out.println(sum);
    }
}

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

int main(){
  int N;
  cin >> N;
  string str;
  cin >>str;
  if(N%2==1){
    cout << "No"<<endl;
    return 0;
  }
  string s1=str.substr(0, str.size()/2);
  string s2=str.substr(str.size()/2, str.size()/2);
  if(s1==s2) cout<<"Yes"<<endl;
  else cout <<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;

const int INF = 1e9 ;
const int maxN = 1e5 + 5;

int n,Q;
int a[maxN];
int X[maxN];
int n1,n2,n3,n4; 
int main()
{
	for(int i=1;i<=4;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+5);
	if(a[1] == 1 && a[2] == 4 && a[3] == 7 && a[4] == 9)
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}
	return 0;
} 

Measured memory_bytes: 256
INPUT= input()
n, y = INPUT.strip().split(" ")
n = int(n)
y = int(y)
flag = 0
for i in range(n+2):
    for j in range(i+1,n+2):
        if flag == 1:
            break
        if y ==10000 *i + 5000* (j-i-1) + 1000 * (n-j+1):
            print("{} {} {}".format(i, j-i-1, n-j+1))
            flag = 1
            break
if flag == 0:
    print("-1 -1 -1")

Measured memory_bytes: 3064
/**
 *    author:  Mohamad Milhem
 *    created: 2020-04-30-01.07.48
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(5)
int n, c;
vector<pair<int,int>> wv;
ll dp[100005][105];



ll calc(int idx , int rem){
    if (rem < 0)return -1e9;
    if (idx == n)return 0;


    if (dp[rem][idx] != -1)return dp[rem][idx];

    return dp[rem][idx] = max(wv[idx].second + calc(idx + 1 , rem - wv[idx].first) , calc(idx + 1 , rem));


}



int main(){

    FAST;
    cin >> n >> c;
    for (int i = 0; i < n ; i++){
        int x, y;
        cin >> x >> y;
        wv.push_back({x,y});
    }
    sort(wv.begin() , wv.end());
    memset(dp , -1 , sizeof dp);

    cout << calc(0 , c) << endl;



    return 0;
}


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

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

int main() {
  int N; cin >> N;
  int ans = 1000000000;
  rep2(i, 1, N) {
    int A = i;
    int B = N - i;
    ans = min(findSumOfDigits(A) + findSumOfDigits(B), ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=n//2019
b=m//2019
if n*m%2019==0 or b-a>=1:
  print(0)
else:
  best=2018
  for c in range(n%2019,m%2019):
    for d in range(c+1,m%2019+1):
      if c*d%2019<best:
        best=c*d%2019
  print(best)

Measured memory_bytes: 9128
#include<iostream>
#include<string>
#include<climits>
#define MAX 2000000
using namespace std;

const int INFTY = INT_MAX;
int H, A[MAX+1];

void maxHeapify(int i){
    int l = 2*i;
    int r = 2*i + 1;
    int largest;

    if (l <= H && A[l] > A[i]) largest = l;
    else largest = i;

    if (r <= H && A[r] > A[largest]) largest = r;

    if (largest != i){
        swap(A[largest], A[i]);
        maxHeapify(largest);
    }else return;
}

int extract(){
    int maxkey;
    if(H < 1) return -INFTY;

    maxkey = A[1];
    A[1]= A[H--];
    maxHeapify(1);
    return maxkey;
}

void heapIncreasingKey(int i, int key){
    if(key < A[i]) return;
    A[i] = key;
    while(i > 1 && A[i/2] < A[i]){
        swap(A[i/2], A[i]);
        i = i/2;
    }
}

void insert(int key){
    H++;
    A[H] = -INFTY;
    heapIncreasingKey(H, key);
}

int main(){
    int key;
    string cmd;

    while(1){
        cin >> cmd;
        if(cmd == "end")  break;
        else if(cmd == "insert"){
            cin >> key;
            insert(key);
        }else if (cmd == "extract"){
            cout << extract() << "\n";
        }
    }

    return 0;
}



Measured memory_bytes: 7060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

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

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        char[] s=cin.next().ToCharArray();
        s[3]='8';
        for(int i=0;i<s.Length;i++)Console.Write(s[i]);
        Console.WriteLine();
    }
}



class Scanner
{
    string[] s;
    int i;

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

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

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

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

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

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

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


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

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


Measured memory_bytes: 13140
<?php
// See: https://atcoder.jp/contests/abc052/tasks/arc067_a

// 単一行 $input[0], $input[1]...
//$single_line_input = fgets(STDIN);
//$input = explode(" ", $single_line_input);

// 複数行 $input[0][0], $input[1(行)][0(桁)]
while ($line = fgets(STDIN)) {
    $tmp[] = trim($line);
}
foreach ($tmp as $key => $value) {
    $input[] = explode(" ", $value);
}

// --- ↓ ここから

$n = $input[0][0];
$ans = 0;

for ($i = 0; $i < $n; $i++){
    if(($i+1) % 2 == 0){

    }else{
        if(is_odd($input[1][$i])){
            $ans ++;
        }
    }
}

echo $ans;

function is_odd($n){
    if($n % 2 != 0){
        return true;
    }else{
        return false;
    }
}

function is_even($n){
    if($n % 2 == 0){
        return true;
    }else{
        return false;
    }
}

Measured memory_bytes: 16000
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

n = int(stdin.readline().rstrip())
p = list(map(int, stdin.readline().rstrip().split()))

ans = 0

for i in range(1, n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        ans += 1
    elif p[i-1] > p[i] and p[i] > p[i+1]:
        ans += 1


print(ans)

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  string S; cin >> S;
  int Q; cin >> Q;
  int k[Q]; rep(i,Q) cin >> k[i];
  rep(q,Q) {
    ll d = 0, m = 0, dm = 0;
    ll result = 0;
    rep(i,N) {
      if (i>=k[q]) {
        if (S[i-k[q]]=='D') { d--; dm -= m; }
        else if (S[i-k[q]]=='M') m--;
      }
      if (S[i]=='D') d++;
      else if (S[i]=='M') { m++; dm += d; }
      else if (S[i]=='C') result += dm;
    }
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 1412
from collections import defaultdict

N, W = map(int, input().split())

MAX_NUM = []
len_weights = 0
def dfs(nums):
    if len(nums) == len_weights:
        sum_w = 0
        value = 0
        for i in range(len_weights):
            sum_w += weights[i] * nums[i]
            if nums[i] >= 1:
                value += items[weights[i]][nums[i] - 1]
        return value if sum_w <= W else 0
    value = 0
    i = len(nums)
    for j in range(MAX_NUM[i] + 1):
        value = max(value, dfs(nums + [j]))
    return value

items = defaultdict(list)
for i in range(N):
    w, v = map(int, input().split())
    items[w].append(v)

for v in items.values():
    v.sort(reverse=True)
    for i in range(1, len(v)):
        v[i] = v[i - 1] + v[i]

weights = sorted(items.keys())
len_weights = len(weights)
for w in weights:
    MAX_NUM.append(min(W // w, len(items[w])))
print(dfs([]))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int L, R, d;
	cin >> L >> R >> d;

	int ans = 0;
	for (int i = L; i <= R; ++i) {
		if (i % d == 0) { ++ans; }
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n,m; cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
    return 0;
}

Measured memory_bytes: 256
def resolve():
    s = input()

    for i in range(len(s)):
        curr = s[i]
        if i % 2 == 0:
            if curr not in ["R", "U", "D"]:
                print("No")
                return
        else:
            if curr not in ["L", "U", "D"]:
                print("No")
                return
    print("Yes")
    
resolve()

Measured memory_bytes: 38384
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    long[] h = new long[n];
    for(int i = 0;i<n;i++){
      h[i] = sc.nextLong();
    }
    Arrays.sort(h);
    long dmg = 0l;
    for(int i = 0;i<n-k;i++){
      dmg += h[i];
    }
    System.out.println(dmg);

  }
}


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

int main(){
    
    long long int N, i, sum, sq_sum, k, ans;
    cin >> N;
    long long int a[N];
    sum = 0;
    sq_sum = 0;
    
    for (i = 0; i < N; i++){
        cin >> a[i];
        
        sum += a[i];
        sum %= ((long long int)pow(10, 9) + 7);
        sq_sum += a[i] * a[i];
        sq_sum %= ((long long int)pow(10, 9) + 7);
        
    }
    
    k = (sum * sum - sq_sum) % ((long long int)pow(10, 9) + 7);
    
    if ( k % 2 == 0 ){
        ans = k / 2;
    } else {
        ans = ( k + (long long int)pow(10, 9) + 7 ) / 2;
    }
    
    cout << ans;

    return 0;
}


Measured memory_bytes: 5156
n=int(input())
a=list(map(int,input().split()))
a.insert(0,0)
a.insert(n+1,0)
total=0
for i in range(n+1):
    total+=abs(a[i+1]-a[i])
for i in range(n):
    print(total-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]))

Measured memory_bytes: 14048
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll a,b;cin >> a>> b;
  ll sum = a+b;
  if(sum%2==1) cout << "IMPOSSIBLE" << endl;
  else cout << sum/2 << endl;
  return 0;
}


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

using namespace std;

typedef long double db;
typedef long long ll;
typedef pair<db, db> pd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define mod 1000000007
#define maxn 100005

ll n, m, q, t, k;
ll a[maxn];



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

	cin >> n;
	ll tmp = ll(ceil(n / db(1.08)));
	if(n != ll(floor(tmp * 1.08)))
		cout << ":(";
	else cout << tmp;

	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;
typedef long long ll;


int main(int argc, char *args[]) {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	
	for (int i = 1; i < n; i++) {
		int counter = 0;
		
		for (char c = 'a'; c <= 'z';c++) {
			bool left = false, right = false;
			for (int j = 0; j < i;j++) {
				if (s[j] == c) left = true;
			}
			for (int j = i; j <= n;j++) {
				if (s[j] == c) right = true;
			}
			if (left && right) counter++;
		}
		if (ans < counter)ans = counter;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

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

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n, t;
    cin >> n >> t;

    vector<int> a(n);
    int mini = IINF;
    int maxProfit = -1;
    unordered_map<int, int> mp;
    rep(i, n){
        cin >> a[i];
        chmax(maxProfit, a[i] - mini);
        ++mp[a[i] - mini];
        chmin(mini, a[i]);
    }

    cout << mp[maxProfit] << endl;

    cout << flush;

    return 0;
}

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

int main() {
  string s,ans;

  cin >> s;

  if(s=="AAA") {
    ans="No";
  }
  else if(s=="BBB") {
    ans="No";
  }
  else {
    ans="Yes";
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	
	int latte = 1, ans = 0;
	std::set<i64> st;
	for(int i = 0; i < 10; i++) latte *= 4;
	for(int i = 0; i < latte - 1; i++) {
		std::string s = "";
		int tmp = i;
		std::vector<bool> used(3, false);
		for(int k = 0; k < 10; k++) {
			if(tmp % 4 == 0) {
				s += '3';
				used[0] = true;
			} else if(tmp % 4 == 1) {
				s += '5';
				used[1] = true;
			} else if(tmp % 4 == 2) {
				s += '7';
				used[2] = true;
			}
			tmp /= 4;
		}
		if(!(used[0] and used[1] and used[2])) continue;
		if(!s.size()) continue;
		if(std::stoll(s) <= n) st.insert(std::stoll(s));
	}
	printf("%d\n", st.size());
	return 0;
}


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

int main()
{
  int n, tmp;
  cin >> n;
  map<int, int> odd, even;

  for (int i = 0; i < n; ++i)
  {
    cin >> tmp;
    if (i % 2 != 0)
    {
      if (odd.count(tmp))
        ++odd[tmp];
      else
        odd[tmp] = 1;
    }
    else
    {
      if (even.count(tmp))
        ++even[tmp];
      else
        even[tmp] = 1;
    }
  }
  
  pair<int, int> e1 = make_pair(0, -1), o1 = make_pair(0, -1);
  for (auto o : odd) {
    if (o1.second < o.second) o1 = o;
  }
  for (auto e : even) {
    if (e1.second < e.second) e1 = e;
  }
  
  if (e1 != o1) cout << n - e1.second - o1.second << "\n";
  else {
    pair<int, int> e2 = make_pair(0, 0), o2 = make_pair(0, 0);
    
    for (auto o : odd) {
      if (o.first == o1.first) continue;
      if (o2.second < o.second) o2 = o;
    }
    
  	for (auto e : even) {
      if (e.first == e1.first) continue;
      if (e2.second < e.second) e2 = e;
  	}
    cout << min(n - e1.second - o2.second, n - e2.second - o1.second) << "\n";
  }
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
using namespace std;

class S {
  public:
    S(int length) : length(length) { part.insert(make_pair(length + 1, length + 1)); }
    void add_ap(int pos, int power) {
      int start = max(pos - power, 0), end = min(pos + power, length);
      auto it = part.lower_bound(start);
      if (it != part.begin()) it--;
      while (true) {
        if (end < it->first) { // (A)(B)
          part.insert(make_pair(start, end));
          break;
        } else if (start < it->first) {
          if (end <= it->second) { // (A()B)
            part.insert(make_pair(start, it->second));
            part.erase(it);
            break;
          } else { // (A(B)...
            part.erase(it++);
          }
        } else if (start <= it->second) {
          if (end <= it->second) { // (B(A))
            break;
          } else { // (B()A...
            start = it->first;
            part.erase(it++);
          }
        } else { // (B)(A...
          it++;
        }
      }
    }
    bool covered() {
      auto f = part.begin();
      return f != part.end() & f->first == 0 & f->second == length;
    }
  private:
    int length;
    map<int, int> part;
};

int main() {
  int n, w, h;
  cin >> n >> w >> h;
  S xs = S(w), ys = S(h);
  bool covered = false;
  int x, y, p;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> p;
    xs.add_ap(x, p);
    ys.add_ap(y, p);
    if (xs.covered() | ys.covered()) {
      covered = true;
      break;
    }
  }
  cout << (covered ? "Yes" : "No") << endl;
  return 0;
}

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

#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (int)(1000000007)
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 9999999999999999
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 100005
#define mxnn 2000005
int val[mxn],wei[mxn],dp[105][mxn];

int32_t main(){
sp;
int n,w;
memset(dp,-1,sizeof dp);
cin >>n >>w;
for(int i = 1;i<=n;i++) cin >> wei[i] >> val[i];
int ans = 0;
for(int i = 0;i<105;i++) for(int j = 0;j<mxn;j++) dp[i][j] = inf;
dp[0][0] = 0;
for(int i = 1;i<=n;i++) dp[i][0] = 0;
for(int i = 1;i<=n;i++){
    for(int j = 1;j<mxn;j++){
        dp[i][j] = dp[i-1][j];
        if(j-val[i]>=0) dp[i][j] = min(dp[i][j],dp[i-1][j-val[i]]+wei[i]);
    }
}
for(int i = 0;i<mxn;i++) if(dp[n][i]<=w) ans = i;
cout<<ans;
return 0;
}


Measured memory_bytes: 82304
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		int t;
		cin >> t;
		cnt += t != i;
	}
	puts(cnt <= 2 ? "YES" : "NO");
	return 0;
}


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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b;
    cin >> a >> b;
    int c = b - a;
    int sum = 0;
    for (int i = 1; i <= c; i++) {
        sum += i;
    }
    cout << sum - b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  ll a, b, k;cin>>a>>b>>k;
  cout<<max(0LL, a-k)<<" ";
  cout<<max(0LL, b-max(0LL, k-a))<<endl;
  return 0;
}


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


int main(void){
    int n;
    cin >> n;
    int ans;
    if(n%2 == 0){
        ans = n;
    }else{
        ans = n*2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,q;cin>>n>>m>>q;
    string s[n];
    rep(i,0,n)cin>>s[i];
    int sum[n+1][m+1],hen[n+1][m+1];
    memset(sum,0,sizeof sum);
    memset(hen,0,sizeof hen);
    rep(i,0,n){
        rep(j,0,m){
            sum[i+1][j+1]=sum[i][j+1]+sum[i+1][j]-sum[i][j];
            if(s[i][j]=='1')sum[i+1][j+1]++;
            hen[i+1][j+1]=hen[i][j+1]+hen[i+1][j]-hen[i][j];
            if(i>0&&s[i][j]=='1'&&s[i-1][j]=='1')hen[i+1][j+1]++;
            if(j>0&&s[i][j]=='1'&&s[i][j-1]=='1')hen[i+1][j+1]++;
        }
    }
    int tate[n+1][m+1],yoko[n+1][m+1];
    memset(tate,0,sizeof tate);
    memset(yoko,0,sizeof yoko);
    rep(i,1,m){
        rep(j,0,n){
            tate[j+1][i+1]=tate[j][i+1];
            if(s[j][i-1]=='1'&&s[j][i]=='1')tate[j+1][i+1]++;
        }
    }
    rep(i,1,n){
        rep(j,0,m){
            yoko[i+1][j+1]=yoko[i+1][j];
            if(s[i][j]=='1'&&s[i-1][j]=='1')yoko[i+1][j+1]++;
        }
    }
    rep(i,0,q){
        int a,b,c,d;cin>>a>>b>>c>>d;
        int tyou=sum[c][d]-sum[c][b-1]-sum[a-1][d]+sum[a-1][b-1];
        int he=hen[c][d]-hen[c][b-1]-hen[a-1][d]+hen[a-1][b-1];
        he-=tate[c][b]-tate[a-1][b]+yoko[a][d]-yoko[a][b-1];
        cout<<tyou-he<<endl;
    }
}



Measured memory_bytes: 69504
{-# LANGUAGE CPP #-}
module Main where

import qualified Data.Vector as V 
import qualified Data.Map.Strict as M
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

dump :: (Show a) => a -> IO()
#if __GLASGOW_HASKELL__ >= 850
dump x = print x
#else
dump _ = pure ()
#endif

readint :: IO Int
readint = (fst . fromJust . BS.readInt) <$> BS.getLine

readvec :: IO [Int]
readvec = (fmap (read . BS.unpack) . BS.words) <$> BS.getLine

newtype UF a = UF (M.Map a a) deriving (Show) -- Map node parent

makeuf :: Int -> UF Int
makeuf n = let m = M.fromList $ zip [0..n] [0..n]
                in UF m

union :: (Eq a, Ord a) => a -> a -> UF a -> UF a
union l r uf@(UF m) = let lp = find l uf
                          rp = find r uf
                      in if lp == rp
                         then uf
                         else if size l uf < size r uf
                              then UF $ M.update (const $ Just rp) lp m
                              else UF $ M.update (const $ Just lp) rp m

find :: (Eq a, Ord a) => a -> UF a -> a
find x uf@(UF m) = let px = m M.! x
                in if px == x
                   then px
                   else find px uf -- TODO 貼り直し

size :: (Eq a, Ord a) => a -> UF a -> Int
size x (UF m) = M.size $ M.filter (\par -> par==x) m

main :: IO()
main = do
  [h, w] <- readvec
  [h', w'] <- readvec
  print $ (h - h') * (w - w')


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

int main() {
    int n;
    cin >> n;
    vector<mint> a(n), s(n);
    rep(i,n) {
        cin >> a[i];
        if (i == 0) s[i] = a[i];
        else s[i] = s[i-1] + a[i];
    }
    mint ans = 0;
    for (int i = 0; i < n-1; i++) {
        mint sh = s[n-1]-s[i];
        ans += a[i] * sh;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6392
#include <stdio.h>

#pragma warning(disable:4996)


int main() {
	//入力
	int D, T, S;
	(void)scanf("%d%d%d", &D, &T, &S);


	//待ち合わせ場所までにかかる時間を計算する関数
	float time(int, int);


	//出力
	if (time(D, S) <= T)printf("Yes"); else printf("No");
}



float time(int D, int S) {
	return (float)D / (float)S;
}

Measured memory_bytes: 1716
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef array<int,2> pii; 

const int N = 2e3 + 5;
const ll inf = 1e16;

ll dp[N], ndp[N];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> a(n);
	vector<pii> v(n);
	rep(i,0,n){
		cin >> a[i];
		v[i] = pii{a[i],i};
	}
	sort(v.rbegin(), v.rend());
	fill(dp,dp+N, -inf);
	dp[0] = 0;
	rep(i,0,n){
		fill(ndp,ndp+N, -inf);
		int cur = v[i][1];
		rep(lft,0,n+1){
			int ltar = lft;	
			ll lgain = 1LL * a[cur] * abs(ltar-cur);
			gmax(ndp[lft+1], dp[lft] + lgain);
			int rtar = n-1-(i-lft);	
			ll rgain = 1LL * a[cur] * abs(rtar-cur);
			gmax(ndp[lft], dp[lft] + rgain);
		}
		swap(dp,ndp);
	}
	ll ans = *max_element(dp,dp+n+2);
	cout << ans << '\n';
}


Measured memory_bytes: 3720
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  if(a <= 0 && 0 <= b){
    cout << "Zero" << endl;
  }
  else if(0 < a){
    cout << "Positive" << endl;
  }
  else if(b < 0){
    if((b - a) % 2 == 0){
      cout << "Negative" << endl;
    }
    else{
      cout << "Positive" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
int n,k,p[200005],pos[200005],i,a[200005],b[200005],l,r,tot0=0,tot1=0,hd0=1,hd1=1,x,y;
set<int>st;
set<int>::iterator it;
multiset<int>mst0,mst1;
multiset<int>::iterator it2;
struct node
{
	int t,p;
	bool operator<(const node&y)const
	{
		return t<y.t||(t==y.t&&p<y.p);
	}
}u[400005],v[400005];
set<node>st2; 
bool cmp(node a,node b){return a.t<b.t||(a.t==b.t&&a.p<b.p);}
int main()
{
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",&p[i]),pos[p[i]]=i;
	st.clear();
	for(i=0;i<n;i++)
	{
		it=st.upper_bound(pos[i]);
		if(it!=st.end())a[pos[i]]=(*it);
		st.insert(pos[i]);
	}
	st.clear();
	for(i=n-1;i>=0;i--)
	{
		it=st.lower_bound(pos[i]);
		if(it!=st.begin())
		{
			--it;
			b[pos[i]]=(*it);
		}
		st.insert(pos[i]);
	}
	for(i=1;i<=n;i++)
	{
		if(a[i]==0)continue;
		if(a[i]-i+1>k)continue;
		l=max(1,a[i]-k+1);
		r=i+1;
		u[++tot0]=(node){l,i};
		u[++tot0]=(node){r,-i};
	}
	for(i=1;i<=n;i++)
	{
		if(b[i]==0)continue;
		if(i-b[i]+1>k)continue;
		l=max(1,i-k+1);
		r=b[i]+1;
		v[++tot1]=(node){l,i};
		v[++tot1]=(node){r,-i};
	}
	sort(u+1,u+tot0+1,cmp);
	sort(v+1,v+tot1+1,cmp);
	for(i=1;i<=n-k+1;i++)
	{
		while(hd0<=tot0&&u[hd0].t<=i)
		{
			if(u[hd0].p<0)mst0.erase(-u[hd0].p);
			else mst0.insert(u[hd0].p);
			hd0++;
		}
		while(hd1<=tot1&&v[hd1].t<=i)
		{
			if(v[hd1].p<0)mst1.erase(-v[hd1].p);
			else mst1.insert(v[hd1].p);
			hd1++;
		}
		if(mst0.empty())st2.insert((node){0,0});
		else
		{
			x=*mst0.begin();
			it2=mst1.end();
			--it2;
			y=*it2;
			st2.insert((node){x,y});	
		}
	}
	printf("%d\n",(int)st2.size());
} 

Measured memory_bytes: 37760
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<limits>

using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	long long total = 1, reject = 1;
	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 0) {
			total *= 3;
			reject *= 2;
		}
		else {
			total *= 3;
			reject *= 1;
		}
	}
	cout << total - reject << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main()
{
    char c;
    cin >> c;
    if (c <= 'Z')
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }
}

Measured memory_bytes: 3632
#include<cstdio>

using namespace std;

double num(double);

int main(void){
	double a,sum;

	while((scanf("%lf",&a))!=EOF){
		sum=num(a);
		printf("%.6f\n",sum);
	}

	return 0;
}

double num(double x){
	int i;
	double data[11],sum=0;

	data[1]=x;
	for(i=2;i<=10;i++){
		if(i%2==0){
			data[i]=data[i-1]*2;
		}
		else{
			data[i]=data[i-1]/3;
		}
	}
	for(i=1;i<=10;i++){
		sum+=data[i];
	}

	return sum;
}

Measured memory_bytes: 0
use proconio::input;

fn main() {
    input! {
        n: u64,
    }
    let mut ans = 0;
    for i in 1..n+1 {
        ans += i * sum_of_geometric_progressions(n/i);
    }
    println!("{}", ans);
}

fn sum_of_geometric_progressions(n: u64) -> u64
{    
    n * (n + 1) / 2
} 

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

Measured memory_bytes: 596