akhauriyash/Code-Regression huggingface dataset:
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = longList()
    val minusCount = a.count { it < 0 }
    val aa = a.map(Math::abs)
    val sum = aa.sum()
    if (minusCount % 2 == 0) {
        println(sum.toString())
    } else {
        val sub = aa.min()!!
        println((sum - (2 * sub)).toString())
    }
}


Measured memory_bytes: 60116
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d = 0, e = 0, count = 0;
	cin >> a;
	if (a % 2 == 0) {
		cout << a;
	}
	else { cout << a * 2; }

	return 0;
}

Measured memory_bytes: 256
//package april2020;

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		FastReader scn = new FastReader();
		OutputStream out = new BufferedOutputStream ( System.out );
		int n =scn.nextInt();
		int k = scn.nextInt();
		int[] a = new int[n];
		for(int  i=0;i<n;i++) {
			a[i] = scn.nextInt();
		}
		
		boolean[] dp = new boolean[k+1];
		for(int stones = 0;stones<=k;stones++) {
			for(int x:a) {
				if(stones>=x&&!dp[stones-x]) {
					dp[stones]=true;
				}
			}
		}
		out.write((dp[k]?"First\n":"Second\n").getBytes());
		out.close();
	}
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


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

int n, k;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    int lim = (n - 1) * (n - 2) / 2;

    if (k > lim) {
        cout << -1;
        return 0;
    }

    vector<pair<int, int>> edges;
    for (int i = 2; i <= n; ++i)
        edges.push_back({1, i});

    for (int i = 2; i < n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if (lim > k) {
                edges.push_back({i, j});
                --lim;
            } else break;
        }
    }

    cout << edges.size() << '\n';
    for (auto edge : edges) cout << edge.first << ' ' << edge.second << '\n';
}


Measured memory_bytes: 3636
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll n;
vector<pair<ld,ld>> p;
ld f(ld x, ld y){
    ld ma = 0;
    rep(i, n){
        ma = max(ma, sqrt(pow(x - p[i].first, 2.0) + pow(y - p[i].second, 2.0)));
    }
    return ma;
}
ld g(ld x){
    
    ld l = -1000;
    ld r = 1000;

    while(abs(l - r) > 1e-6){
        ld mid1 = (l * 2 + r) / 3.0;
        ld mid2 = (r * 2 + l) / 3.0;
        if(f(x, mid1) > f(x, mid2)){
            l = mid1;
        } else {
            r = mid2;
        }
    }

    return f(x, l);
}
int main(void){
    cin >> n;
    p.resize(n);
    rep(i, n){
        ld a, b;
        cin >> a >> b;
        p[i] = {a, b};
    }

    ld lx = -1000;
    ld rx = 1000;

    while(abs(lx - rx) > 1e-6){
        ld mid1 = (lx * 2 + rx) / 3.0;
        ld mid2 = (rx * 2 + lx) / 3.0;
        if(g(mid1) > g(mid2)){
            lx = mid1;
        } else {
            rx = mid2;
        }
    }
    cout << fixed << setprecision(15) << g(lx) << endl;
}



Measured memory_bytes: 3764
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000 //1e16
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,sum=0,flag=0,count=0;
    string S,T,U; 
    int h;
    cin>>h>>n;
    vi a(n),b(n);
    rep(i,0,n) cin>>a[i]>>b[i];
    vi dp(h+1,INF);
    dp[0]=0;
    rep(i,0,h+1)
    {
        rep(j,0,n)
        {
            // if(a[j]>=i)
            {
                dp[i]=min(dp[i],dp[max(i-a[j],0ll)]+b[j]);
            }
        }
    }
    cout<<dp[h];
}

 

signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3696
//Created by rect0r
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define F first
#define S second
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef vector<char> vc;
typedef pair<int, int> pii;

void solve() {
	string s;
	cin >> s;
	int a[2]={0};
	for(int i=0; i<s.length(); i++)
		a[s[i]-'A']++;
	if(a[0]!=0 && a[1]!=0)
		cout << "Yes";
	else 
		cout << "No";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll T;
	//cin >> T;
	T = 1;
	while(T--) {
		solve();
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 508
def bigger?(s,t)
  return s>t ? 1 : 0
end

w,h,n=gets.split.map &:to_i
pt=[nil,0,w,0,h]

n.times do
  a=gets.split.map &:to_i
  a[2]%2==1&&pt[a[2]]<a[a[2]/3]&&pt[a[2]]=a[a[2]/3]
  a[2]%2==0&&pt[a[2]]>a[a[2]/3]&&pt[a[2]]=a[a[2]/3]
end

puts (pt[2]-pt[1])*(pt[4]-pt[3])*bigger?(pt[2],pt[1])*bigger?(pt[4],pt[3])


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

int main() {
	int K, T;
	cin >> K >> T;
	vector<int> A(T+1);
	for (int i = 0; i < T; i++)
		cin >> A[i];
	int ans = 0;
	while (1) {
		sort(A.rbegin(), A.rend());
		if (A[0] == 0) break;
		if (A[1] == 0) {
			ans += A[0]-1;
			break;
		} else {
			A[0]--;
			A[1]--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(10)





void solve() {

	string s;
	cin >> s;
	string ans;
	for(int i =0 ; i < s.length(); i++) {
		cout << 'x';
	}
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	solve();

	return 0;
}

Measured memory_bytes: 3628
N,M = map(int,input().split())


#print(A)
def comp(lst1,lst2):
    ret = []
    for i in lst1:
        if i in lst2:
            ret.append(i)
    return ret
ret = list(map(int,input().split()))
ret = ret[1:]
#print(ret)
for i in range(1,N):
    lst = list(map(int,input().split()))
    ret = comp(ret,lst[1:])
    #print(ret)
print(len(ret))

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    int ans = 0;
    int e[7];
    e[0] = 1;
    rep2(i, 1, 6) e[i] = 10*e[i-1];
    rep2(i, 1, N){
        int a = i%10;
        int b = i;
        int c = 1;
        while(b >= 10){
            b /= 10;
            c++;
        }
        if(c == 1){
            ans++;
            continue;
        }
        if(a == 0) continue;
        if(a == b) ans += 2;
        rep2(j, 2, c-1){
            ans += 2*(e[j-2]);
        }
        if(a == b){
            ans += 2 * (i-a-b*e[c-1])/10;
            ans += 1;
        }
        elif(a < b){
            ans += 2*e[c-2];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
char ch[20];
map<string, int>m;
map<string, int>::iterator it;
int main(void)
{
	int n;
	long long sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{

		cin >> ch;

		sort(ch, ch + 10);

		ch[10] = '\0';

		if (!m.count(ch))

		{

			m[ch] = 0;

		}

		m[ch] += 1;

	}

	for (it = m.begin(); it != m.end(); it++)

	{

		int k = it->second;

		for (int i = 0; i < k; i++)

		{

			sum += i;

		}

	}

	cout << sum << endl;

	return 0;

}


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

int main(int argc, char *argv[]) {
  int n;
  std::string s;
  std::cin >> n >> s;
  char c = s.at(0);
  int count = 1;
  for (char d : s) {
    if (c != d) {
      c = d;
      ++count;
    }
  }
  std::cout << count << std::endl;
}


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


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

/* vector<int> A(N); 
    vector<pair<int, int> > tasks; ＃ソートした場合、１つ目でソート
　tie(b, a) = p.at(i); #pairを分割
    tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
　xの二乗:  pow(x, 2.0) 
    小さい順: sort(v.begin(), v.end());
    大きい順: reverse(v.begin(), v.end());
    int: -2,147,483,648 ～ 2,147,483,647
    ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
    // int型の2次元配列(3×4要素の)の宣言
    vector<vector<int>> data(3, vector<int>(4));
*/
 
int main() {
  
  ll N, A, B, a, b, c, d,e, count=0, ans=0;
  cin >> N >> A >> B;
  c= N/(A+B);
  d=c*A;
  e= N-c*(A+B);
  if (e>=A) d+=A;
  else d+=e;
  
  
  cout << d << endl;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().Split().Select(int.Parse).ToArray();
        WriteLine(n[0] + n[1] < 10 ? (n[0] + n[1]).ToString() : "error");
    }
}


Measured memory_bytes: 18920
from bisect import bisect_left

# n >= 6
def sieve_fast(n):
    correction = (n%6>1)
    n = {0:n,1:n-1,2:n+4,3:n+3,4:n+2,5:n+1}[n%6]
    sieve = [True] * (n//3)
    sieve[0] = False
    for i in range(int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      ((k*k)//3)      ::2*k]=[False]*((n//6-(k*k)//6-1)//k+1)
        sieve[(k*k+4*k-2*k*(i&1))//3::2*k]=[False]*((n//6-(k*k+4*k-2*k*(i&1))//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

ps = sieve_fast(200010)
while True:
  N,P = map(int,input().split())
  if N < 0:
    break
  pos = bisect_left(ps,N+1)
  L = []
  for i in range(110):
    for j in range(i,110):
      L.append(ps[pos+i]+ps[pos+j])
  L.sort()
  print(L[P-1])


Measured memory_bytes: 6956
#include<stdio.h>
int main(){
  char b;
  scanf("%c",&b);
  if(b=='A')
    printf("T\n");
  else if(b=='T')
    printf("A\n");
  else if(b=='G')
    printf("C\n");
  else
    printf("G\n");
  return 0;
}


Measured memory_bytes: 128
s=chomp(readline())
k=parse(Int,readline())
t=""
for c=s[1:end-1]
	x=26-(Int(c)-97)
	if c=='a'
		print('a')
	elseif x<=k
		k-=x
		print('a')
	else
		print(c)
	end
end
c=s[end]
x=(Int(c)-97+k)%26+97
println(Char(x))


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

const int N = 1e5 + 233;

int n; std::vector<std::pair<int, int>> v;
std::map<int, int> map;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    ++map[x];
  }
  if (map.size() > 3) {
    puts("No");
    return 0;
  }
  for (auto w : map)
    v.push_back({ w.first, w.second });
  if (v.size() == 1) {
    if (v.front().first == 0)
      puts("Yes");
    else
      puts("No");
  } else if (v.size() == 2) {
    if (v[0].first != 0 && v[1].first != 0)
      puts("No");
    else {
      if (v[1].first == 0)
        std::swap(v[0], v[1]);
      if (v[1].second == v[0].second * 2)
        puts("Yes");
      else
        puts("No");
    }
  } else {
    if (v[0].second != v[1].second || v[1].second != v[2].second) {
      puts("No"); return 0;
    }
    if (v[0].first ^ v[1].first ^ v[2].first) {
      puts("No");
      return 0;
    }
    puts("Yes");
  }
  return 0;
}


Measured memory_bytes: 3840
n,k = map(int,input().split())
a = list(map(int,input().split()))
##dp[i][j]:i番目までの元を用いたとき、j個の石の山についてどっちが勝つか
dp = [True]*(k+1)

dp[0] = False


for j in range(1,k+1):
  for i in range(n):
    if j>=a[i]:
      if not dp[j-a[i]]:
        dp[j] = True
        break
    dp[j] = False
if dp[k]:
  print("First")
else:
  print("Second")

Measured memory_bytes: 42348
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int answer = 0;
    int[] a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int amax = a[n-1];
    boolean[] isNotPrime = new boolean[amax + 1];
    Arrays.fill(isNotPrime, true);
    for(int i = 0; i < n; i++){
      int div = a[i];
      if(i > 0 && a[i-1] == div) {
        isNotPrime[div] = false;
        continue;
      }
      for(int j = 2; j * div <= amax; j++){
        isNotPrime[j * div] = false;
      }
    }
    for(int i = 0; i < n; i++){
      if(isNotPrime[a[i]] == true) answer++;
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 59968
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 200001;

int main(){
    int n, m, v[N];
    scanf("%d%d", &n, &m);
    int sm = 0;
    for(int i = 0; i<n; ++i){
        scanf("%d", v+i);
        sm += v[i];
    }
    sort(v, v+n);
    reverse(v, v+n);
    double mn = (sm * 1.0) * (1.0 / (4.0 * m));
    int yes = 0;
    for(int i = 0; i<n; ++i){
      if(v[i] >= mn)++yes;
      else break;
    }
    if(yes >= m)puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	bool pres = false;
	while(n > 0)
	{
		int x = n % 10;
		if(x==7)
		{
			pres = true;
			break;
		}
		n = n/10;
	}
	if(pres)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
using namespace std;
int main(void){
    int N;
    cin>>N;
    vector<double>a(N,0);
    for(int i=0;i<N;i++){//入力
        cin>>a[i];
    }

    sort(a.begin(), a.end());
    double ans=0;
    
    ans=(a[0]+a[1])/2.0;
    if(N!=2){
    for(int j=0;j<N-2;j++){//入力
        ans=(ans+a[j+2])/2.0;
    }
    }

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

Measured memory_bytes: 256
S=input()
now="R"
cnt=0
T=[] #集まる場所のRの位置
L=[] #集まる人数
for s in S:
    if s==now:
        cnt+=1
    else:
        if s=="L":
            T.append(cnt)
            cnt+=1
        else:
            L.append(cnt)
            cnt=1
    now=s
L.append(cnt)
    
A=[]
for i in range(len(L)):
    t=T[i]
    l=L[i]
    for j in range(l):
        if (j+1)==t:
            if t%2==0:
                A.append(l//2)
            else:
                A.append(l-l//2)
        elif (j+1)==(t+1):
            if t%2==0:
                A.append(l-l//2)
            else:
                A.append(l//2)
        else:
            A.append(0)
print(*A)

Measured memory_bytes: 7132
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
const int maxn=4e5+7;
/*Almost copy pasted part :)*/
int dp[maxn];
int seg[4*maxn];
int a[maxn];
void add(int id,int L,int R,int x,int idx){
    if(R<=idx||L>idx){
        return ;
    }
    if(L+1==R){
        seg[id]=max(x,seg[id]);
        return ;
    }
    int mid=(L+R)/2;
    add(id*2+0,L,mid,x,idx);
    add(id*2+1,mid,R,x,idx);
    seg[id]=max(seg[id*2+0],seg[id*2+1]);
}

int get(int id,int L,int R,int l,int r){
    //cout<<l<<" "<<r<<endl;
    if(R<=l||r<=L)
        return 0;
    if(l<=L&&R<=r){
        return seg[id];
    }
    int mid=(L+R)/2;
    return max(get(id*2+0,L,mid,l,r),get(id*2+1,mid,R,l,r));
}


int32_t main(){
    int n;
    cin>>n;
    vector<int> v;
    int mini=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mini=max(mini,abs(a[i]));

    }
    for(int i=1;i<=n;i++){
        a[i]+=(mini+1);
        v.pb(a[i]);
    }
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    for(int i=1;i<=n;i++){
        a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
    }
    /*for(int i=1;i<=n;i++)
        cout<<a[i]<<" ";
    cout<<endl;*/
    for(int i=1;i<=n;i++){
        int t=get(1,1,n+1,1,a[i]);
        /*for(int i=1;i<=n;i++){
            cout<<i<<" &&&&&& "<<get(1,1,n+1,i,i+1)<<endl;
        }*/
        //cout<<endl;
        dp[i]=t+1;
        //cout<<dp[i]<<endl;
        add(1,1,n+1,dp[i],a[i]);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 7364
#include<stdio.h>

int main(){

  int n, sum, i, in;

  while(1){

    scanf("%d",&n);
    
    if(n == 0){
      
      break;
    }
    
    sum = 0;
    
    for(i = 0; i < n/4; i++){
      
      scanf("%d",&in);
      sum += in;
    }
    
    printf("%d\n",sum);
  }
  
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void){
  int N,i,A[1001],count1=0,count2=0;
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<N;i++){
    if(A[i]%2==0){
      count2++;
      if(A[i]%3==0 || A[i]%5==0) count1++;
     }
  }

  if(count1!=count2) printf("DENIED");
  else printf("APPROVED");
  
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int A, B;

  cin >> A >> B;

  cout << 6 - A - B << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
int main()
 
{
 
int a,b;
 
cin>>a>>b;
 
if(a+b>=a-b&&a+b>=a*b){
    cout<<a+b<<endl;
}
 
else if(a-b>=a+b&&a-b>=a*b){
    cout<<a-b<<endl;
}
else if(a*b>=a+b&&a*b>=a-b){
    cout<<a*b<<endl;
}
 
return 0;
 
}

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

int main() {
  int N, K, x, total;
  cin >> N >> K;
  total = 0;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x > K - x)
      total += 2 * (K - x);
    else
      total += 2 * x;
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2e5+2;

int main()
{
    fastio;
    ll i, j, k=0, n, m, t, h;
    vll a;
    cin>>h>>n;
    for ( i = 0; i < n; i++)
    {
        cin>>j;
        a.pb(j);
        k+=j;
    }
    if(k>=h)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
        
    return 0;
}

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

struct obj
{
	int wait_time;
	int rem;
};

bool comp(obj& a, obj& b)
{
	return (a.rem < b.rem);
}

int main()
{
	int i,ans;
	obj a[5];

	for(i=0; i<5; i++)
	{
		cin >> a[i].wait_time;
		a[i].rem = (10-(a[i].wait_time%10))%10;
	}
	sort(a, a+5, comp);

	ans = 0;
	for(i=0; i<5; i++)
	{
		if(i!=4)
			ans += (a[i].wait_time + a[i].rem);
		else
			ans += a[i].wait_time;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){ 
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
       s[i]+=n;
       if(s[i]>'Z')
         s[i] -= 'Z'-'A'+1;
    }
    cout << s;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
from collections import deque

def main():
    N, M = map(int, input().split())

    table_num = deque()
    if N % 2 == 1:
        for i in range(1, M+1):
            table_num.append('%s %s' % (i, N-i))

    else:
        for i in range(1, M+1):
            if i <= N // 4:
                table_num.append('%s %s' % (i, N+1 - i))

            else:
                table_num.append('%s %s' % (i, N - i))
    
    for i_table in table_num:
        print(i_table)
    
    return

if __name__ == '__main__':
    main()

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

int main() {
  int N;
  cin >> N;
  
  vector<int> card(N);
  for (int i=0; i<N; i++) cin >> card.at(i);
  /*
  for (int i=0; i<N-1; i++){
    for (int j=N-1; j>i; j--){
      int tmp;
      if (card.at(j-1)<card.at(j)){
        tmp=card.at(j-1);
        card.at(j-1)=card.at(j);
        card.at(j)=tmp;
      }
    }
  }
  */
  sort (card.begin(),card.end(),greater<int>());
  int a=0,b=0;
  
  for (int i=0; i<N; i+=2) a+=card.at(i);
  for (int i=1; i<N; i+=2) b+=card.at(i);
  
  cout << a-b << endl;
}

Measured memory_bytes: 3524
// g++ -std=c++14 -stdlib=libc++ -O2 ./A.cpp

#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
// #define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  int A, P;
  cin >> A >> P;
  cout << (A*3 + P) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')
  const a = input[0]
  const s = input[1]
  if (a >= 3200) {
    console.log(s)
  } else {
    console.log('red')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 22080
const double = Float64
const int = Int64
const vint = Vector{int}
const vdouble = Vector{double}

int(x) = parse(int,x)
parseint(x) = parse(int, x)

function readint()
  moji = readline(stdin)
  moji = split(moji)
  return map(parseint,moji)

end

function main()
  k = readint()[1]
  a,b = readint()
  if a%k==0 || b÷k - a÷k >= 1 
    println("OK")
  else
    println("NG")
  end
end

main()

Measured memory_bytes: 214428
import sys
def func(w,result):
   list = [1,2,4,8,16,32,64,128,256,512]
   for i in range(len(list)):
       if w == list[i]:
           result.append(list[i])
           w = w - list[i]
           break
       else:
           if list[i] > w :
               result.append(list[i-1])
               w = w - list[i-1]
               break
           elif w > 512:
               result.append(512)
               w = w - 512
               break

   return w
for line in sys.stdin.readlines():
   result = []
   w = int(line)
   while w > 0 :
       w = func(w,result)
   i = len(result)-1
   while i > 0:
       print(result[i],end=' ')
       i -= 1
   print(result[0])
   del(result)

Measured memory_bytes: 7608
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#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 FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int a[100000], b[100000];
int c[100000],in[100000];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int y[],int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		hSwap(y, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, y,left, i - 1, n);
	if (j + 1 <  right)QSort(x, y,j + 1, right, n);
}

int main() {
	int n;
	//*
	scanf("%d", &n);
	REP(i, n) {
		scanf("%d%d", &a[i], &b[i]);
		c[i] = a[i] + b[i];
		in[i] = i;
	}
	/*/
	n = 1e5;
	REP(i, n) {
		a[i] = 1e9-i;
		b[i] = i+1e5;
		c[i] = a[i] + b[i];
		in[i] = i;
		printf("%d %d\n", a[i], b[i]);
	}
	//*/
	QSort(c, in,0, n - 1, 0);
	//ShowData(c, 0, n-1);
	//ShowData(in, 0, n - 1);
	ll ans = 0;
	REP(i, n) {
		ans += (i % 2) ? -b[in[i]] : a[in[i]];
	}
	PRINTL(ans);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){	
	while(1){
	int n;
	int m;
	cin>>n;
	if(n==0)break;
	cin>>m;
	vector<vector<mp> > g(n);
	vector<bool> used(n,true);
	int cnt = 0;
	for(int i=0;i<m;i++){
		int a,b,d;
		scanf("%d,%d,%d",&a,&b,&d);
		d/=100;
		d--;
		g[a].push_back(mp(d,b));
		g[b].push_back(mp(d,a));
	}
	priority_queue<mp,vector<mp>,greater<mp> > q;
	used[0] = false;
	for(int i=0;i<g[0].size();i++){
		q.push(g[0][i]);
	}
	ll res = 0;
	while(!q.empty()){
		mp now = q.top();
		q.pop();
		if(!used[now.second])continue;
		res+=now.first;
		ll next = now.second;
		used[next] = false;
		for(int i=0;i<g[next].size();i++){
		if(used[g[next][i].second])q.push(g[next][i]);
		}

	}
	cout<<res<<endl;
	}

	return 0;
}



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

int main() {
  int N;
  cin >> N;
  for (int i=0; i<N; i++){
    string S;
    cin >> S;
     if (S== "Y"){
    cout << "Four" << endl;
    break;
  }
   else if(i==N-1){
      cout << "Three" << endl;
  }
    }
}
   

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
//#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T>
using Pq = priority_queue<T>;
template <typename T>
using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> S;
    if (S.back() == 's') {
        cout << S + "es" << endl;
    } else {
        cout << S + "s" << endl;
    }
}

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

int main()
{
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < 4; ++i)
  {
    if (s[i] == '+') ++ans;
    else --ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn
import java.io.{BufferedReader,InputStreamReader}

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))
  val Array(n, t) = in.readLine.split(" ").map(_.toInt)
  val a = in.readLine.split(" ")

  val ans = a.tail./:(t.toLong,0)((acc,e) => {
    val ti = e.toInt
    val dur = ti - acc._2
    if(dur < t) (acc._1 + dur, ti)
    else (acc._1 + t, ti)
  })._1

  println(ans)
}

Measured memory_bytes: 77152
#include<stdio.h>
int main(void){
    int D,L;
    int i,count = 0;
    scanf("%d%d",&D,&L);
    for(i = 0;;i++){
        if(D >= L){
            D = D - L;
            count++;
        }
        else if(D >= 1){
            D = D - 1;
            count++;
        }
        else if(D == 0) break;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;
const int large = 2e5+1;
vi vals;
vi edges[large];
map<int,int> valoval;
int seg[4*large];

void ins(int pos,int val,int l, int r, int cpos){
    if(l == r) seg[cpos] = val;
    else{
        int mid = (l+r)/2;
        if(pos <= mid) ins(pos,val,l,mid,2*cpos+1);
        else ins(pos,val,mid+1,r,2*cpos+2);
        seg[cpos] = max(seg[2*cpos+1],seg[2*cpos+2]);
    }
}

int rq(int l1, int r1, int l, int r, int cpos){
    if(l == l1 && r1 == r) return seg[cpos];
    else{
        int mid = (l+r)/2;
        if(r1 <= mid) return rq(l1,r1,l,mid,2*cpos+1);
        else if(l1 > mid) return rq(l1,r1,mid+1,r,2*cpos+2);
        else return max(rq(l1,mid,l,mid,2*cpos+1),rq(mid+1,r1,mid+1,r,2*cpos+2));
    }
}

vi ans;
int cur[large];
void dfs(int pos, int parent,int best){
    int a = rq(0,valoval[vals[pos-1]]-1,0,large,0); a++;
    best = max(best,a);
    int pcur = cur[valoval[vals[pos-1]]];
    cur[valoval[vals[pos-1]]] = a;
    ins(valoval[vals[pos-1]],a,0,large,0);
    ans[pos] = best;
    for(auto &b: edges[pos]){
        if(b == parent) continue;
        dfs(b,pos,best);
    }
    cur[valoval[vals[pos-1]]] = pcur;
    ins(valoval[vals[pos-1]],pcur,0,large,0);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    m0(seg); m0(cur);
    int n; cin >> n;
    vals.resize(n);
    vi vals2(n);
    FOR(i,n){
        cin >> vals[i];
        vals2[i] = vals[i];
    }
    sort(vals2.begin(),vals2.end());
    FOR(i,n){
        valoval[vals2[i]] = i+1;
    }
    ans.resize(n+1);
    FOR(i,n-1){
        int a,b; cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    dfs(1,0,0);
    F0R(i,1,n) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 45064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  string s1 = S.substr(0, N);
  string s2 = S.substr(N);
  map<pair<string,string>, ll> cnt;
  for(int i = 0; i < 1 << N; i++) {
    string red = "";
    string blue = "";
    for(int j = 0; j < N; j++) {
      if (i >> j & 1) {
        red += s2[j];
      } else {
        blue += s2[j];
      }
    }
    string red_rev = red, blue_rev = blue;
    reverse(red_rev.begin(), red_rev.end());
    reverse(blue_rev.begin(), blue_rev.end());

    cnt[mp(red_rev, blue_rev)]++;
  }

  ll ans = 0;
  for (int i = 0; i < 1 << N; i++) {
    string red = "";
    string blue = "";
    for(int j = 0; j < N; j++) {
      if (i >> j & 1) {
        red += s1[j];
      } else {
        blue += s1[j];
      }
    }
    ans += cnt[mp(red, blue)];
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	long long n;
	cin>>n;
	priority_queue<long long> tomo;
	set<long long> num;
	map<long long,long long> cnt;
	long long ans=0;
	for(long long i=0;i<n;i++){
		long long hoge;
		cin>>hoge;
		tomo.push(hoge);
	}

	num.insert(tomo.top());
	cnt[tomo.top()]++;
	tomo.pop();

	while(!tomo.empty()){
		long long now=tomo.top();
		tomo.pop();
		long long big=*(prev(num.end(),1));

		ans+=big;

		cnt[big]--;
		cnt[now]+=2;
		num.insert(now);

		if(cnt[big]==0) num.erase(big);
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 21980
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int gcd(int m, int n) {
  return n ? gcd(n, m % n) : m;
}

int main() {
  vector<int> U;
  for (int i = 1; i <= 30000; ++i) {
    int v = i;
    for (const int p : {2, 3}) {
      while (v % p == 0) v /= p;
    }
    if (v != i) {
      U.push_back(i);
    }
  }

  int N = in();
  if (N == 3) {
    puts("2 5 63");
    return 0;
  }
  while (true) {
    random_shuffle(U.begin(), U.end());
    int g = 0, s = 0;
    for (int i = 0; i < N; ++i) {
      g = gcd(g, U[i]);
      s += U[i];
    }
    if (g == 1 && s % 6 == 0) {
      break;
    }
  }
  pv(U.begin(), U.begin() + N);

  return 0;
}

Measured memory_bytes: 512
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();
		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		Arrays.sort(l);
		int sum = 0;
		for (int i = 0; i < k; i++) {
			sum += l[n-1-i];
		}
		System.out.println(sum);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include<atcoder/all>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;
using namespace atcoder;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

int op(int a, int b){
    return max(a,b);
}

int e(){
    return -INF;
}

int sankou;
bool f(int x){
    return x < sankou;
} 
signed main(){
    int n,q;
    cin >> n >> q;
    segtree<int ,op ,e> seg(n);
    REP(i,n){
        int a1;
        cin >> a1;
        seg.set(i,a1);
    }
    REP(i,q){
        int q1;
        int q2,q3;
        cin >> q1 >> q2 >> q3;
        if(q1==1){
            seg.set(q2-1,q3);
        }
        if(q1==2){
            cout << seg.prod(q2-1,q3) << endl;
        }
        if(q1==3){
            sankou = q3;
            cout << seg.max_right<f>(q2-1)+1 << endl;
        }

    }
    



    return 0;
}

Measured memory_bytes: 9080
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char ss[200000];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),sum=0;
    scanf("%s",ss+1);
    for(int i=1;i<=n;i++)
    {
    	if(ss[i]=='R')sum++;
    }
    int ans=sum;
    for(int i=1;i<=sum;i++)
    {
    	if(ss[i]=='R')ans--;
	}pr2(ans);
    return 0;
}

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

int main(void)
{

    long long a, b, c;
    cin >> a >> b >> c;

    for (int i = 1; i <= b; i++)
    {
        if ((a * i) % b == c)
        {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

int n;
ld x[20];
ld y[20];
ld a[20];
ld dp[1 << 16];
int p[20];
int sz[20];

int get(int a) {
	if (p[a] == a)
		return a;
	return p[a] = get(p[a]);
}

int un(int a, int b) {
	a = get(a);
	b = get(b);
	if (a == b)
		return 0;
	if (sz[a] < sz[b])
		swap(a, b);
	p[b] = a;
	sz[a] += sz[b];
	return 1;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> y[i] >> a[i];
	dp[0] = 1e9 + 100;
	for (int i = 1; i < (1 << n); ++i) {
		vector<tuple<ld, int, int> > eds;
		for (int i = 0; i < n; ++i)
			p[i] = i, sz[i] = 1;
		for (int j = 0; j < n; ++j) {
			if ((i >> j) & 1)
				for (int k = j + 1; k < n; ++k) {
					if ((i >> k) & 1)
						eds.push_back(make_tuple(sqrt((x[j] - x[k]) * (x[j] - x[k]) + (y[j] - y[k]) * (y[j] - y[k])), j, k));
				}
		}
		sort(eds.begin(), eds.end());
		ld sum = 0;
		for (int j = 0; j < eds.size(); ++j) {
			ld x;
			int a, b;
			tie(x, a, b) = eds[j];
			if (un(a, b))
				sum += x;
		}
		sum = -sum;
		int cnt = 0;
		for (int j = 0; j < n; ++j)
			if ((i >> j) & 1)
				sum += a[j], ++cnt;
		dp[i] = max(dp[i], sum / cnt);
		for (int j = i; j > 0; j = (j - 1) & i)
			dp[i] = max(dp[i], min(dp[j], dp[i ^ j]));
	}
	cout.setf(ios::fixed);
	cout.precision(10);
	cout << dp[(1 << n) - 1] << "\n";
	return 0;
}




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

const int INF = 1e9;

int main()
{
  int n, m;
  cin >> n >> m;
  
  vector<P> e(m);
  rep(i, m) cin >> e[i].first >> e[i].second;
  
  vector<int> d(n + 1, INF);
  d[1] = 0;
  
  rep(i, 2) rep(i, m)
  {
    int a = e[i].first, b = e[i].second;
    d[a] = min(d[a], d[b] + 1);
    d[b] = min(d[b], d[a] + 1);
  }
  
  //rep(i, n) cout << d[i+1] << " ";
  
  if(d[n] == 2) cout << "POSSIBLE\n";
  else cout << "IMPOSSIBLE\n";
  
  
  return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(){
 int x, y, i;
 
 for (i = 0; 1; i++){
  scanf("%d %d", &x, &y);

  if(x==0 && y==0){
   break;
  }

  if (x > y){
   printf("%d %d\n", y, x);
  } else {
   printf("%d %d\n", x, y);
  }
 }

 return 0;

}

Measured memory_bytes: 600