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

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

int main() {
    int N;
    cin >> N;
    long long A[N];
    long long sum1 = 0;
    rep(i,N){
        cin >> A[i];
        sum1 += A[i];
    }
    int i;
    long long sum2 = 0;
    long long sum3 = sum1;
    long long res = LONG_LONG_MAX;
    for(i=0;i<N;i++){
        res = min(res,abs(sum2-sum3));
        sum2 += A[i];
        sum3 -= A[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main implements Runnable {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        char[] s = in.nextToken().toCharArray();
        int w = in.nextInt();
        String ans = "";
        for (int i = 0; i < s.length; i+=w) {
            ans += s[i];
        }
        System.out.println(ans);
    }

}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException {super(System.out);}
}
class ContestScanner implements Closeable {
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}


Measured memory_bytes: 24916
import java.util.*;
import java.lang.*;
class Pair<E extends Comparable<E>,F extends Comparable<F>> implements Comparable<Pair<E,F>>{
    E first;
    F second;
    public Pair(E first, F second){
        this.first=first;
        this.second=second;
    }
    public E getFirst(){return first;}
    public F getSecond(){return second;}
    public String toString(){
        return "<"+first.toString()+","+second.toString()+">";
    }
    public int hashCode(){
        return first.hashCode()*30011+second.hashCode()+2;
    }
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Pair another = (Pair) obj;
        return this.getFirst().equals(another.getFirst())&&this.getSecond().equals(another.getSecond());
    }

    public int compareTo(Pair<E,F> another){
        if(this.getFirst().equals(another.getFirst())){
            return this.getSecond().compareTo(another.getSecond());
        }
        return this.getFirst().compareTo(another.getFirst());
    }

}
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Pair<Pair<String,Integer>,Integer>> restaurant = new ArrayList<>(N);
        for(int n=0; n<N; n++){
            restaurant.add(new Pair<>(new Pair<>(sc.next(), -sc.nextInt()),n+1));
        }
        Collections.sort(restaurant);
        for(Pair p:restaurant) System.out.println(p.getSecond());




    }
}

Measured memory_bytes: 21716
#include <iostream>

using namespace std;

int main()
{
        int num[5];

        for (int i = 0; i < 5; i++) {
                cin >> num[i];
        }
        for (int i = 0; i < 4; i++) {
                for (int j = 4; j > i; j--) {
                        if (num[j - 1] < num[j]) {
                                int tmp = num[j - 1];
                                num[j - 1] = num[j];
                                num[j] = tmp;
                        }
                }
        }
        for (int i = 0; i < 5; i++) {
                cout << num[i];
                if (i < 4)
                        cout << " ";
        }
        cout << endl;

        return 0;
}

Measured memory_bytes: 3076
#include<stdio.h>
#include<stdlib.h>

int selectionSort(int*,int);

int main(){

  int n,*a,kaisu;
  int i,j;

  scanf("%d",&n);

  a=(int *)malloc(sizeof(int)*n);

  for(i=0;i<n;i++)scanf("%d",&a[i]);

  kaisu=selectionSort(a,n);

  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n%d\n",kaisu);

  free(a);

  return 0;

}

int selectionSort(int *a,int n){

  int i,j,minj,temp,kaisu=0;
  for(i=0;i<n-1;i++){
    minj=i;
    for(j=i+1;j<n;j++){
      if(a[j]<a[minj]){
	minj=j;
      }
    }
    if(i!=minj){
      temp=a[i];
      a[i]=a[minj];
      a[minj]=temp;
      kaisu++;
    }
  }

  return kaisu;
}

Measured memory_bytes: 604
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int n = nm[0];
        int m = nm[1];
        Console.WriteLine((n * (n - 1) / 2) + (m * (m - 1) / 2)); 
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N = 0;
  int Ans;
  cin >> N;
  
  vector<int> X(N);
  vector<int> Y(N);
  
  for(int i = 0; i < N; i++)
  {
    cin >> X.at(i);
  }
  for(int i = 0; i < N; i++)
  {
    cin >> Y.at(i);
  }
  for(int i = 0; i < N; i++)
  {
    X.at(i) = X.at(i) - Y.at(i);
    if(X.at(i) > 0)
    {
      Ans += X.at(i);
    }
  }
  cout << Ans << endl;
}

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

#define ll long long
#define pb push_back
#define N 1000000007
#define nmax 200001
#define pll pair<ll,ll>
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}

ll extended_gcd(ll a, ll b, ll &x, ll &y) {
	if(a==0) {
		x = 0;
		y = 1;
		return b;
	}

	ll x1,y1;
	ll gcd = extended_gcd(b%a,a,x1,y1);

	x = y1 - (b/a)*x1;
	y = x1;

	return gcd;
}

vector<vector<vector<double>>> dp(303, vector<vector<double>>(303, vector<double>(303,0)));
int main() {
    
   	ll n,c1=0,c2=0,c3=0;
   	cin>>n;

   	for(int i=0;i<n;i++){
   		int a;
   		cin>>a;
   		if(a==1) c1++;
   		else if(a==2) c2++;
   		else if(a==3) c3++;
   	}

   	for(int i=0;i<=c3;i++) {
   		for(int j=0;j<=c2+c3;j++) {
   			for(int k=0;k<=c1+c2+c3;k++) {
   				if(i==0 && k==0 && j==0)
   					continue;
   				double a = (k>0) ? k*dp[i][j][k-1] : 0;
   				double b = (j>0) ? j*dp[i][j-1][k+1] : 0;
   				double c = (i>0) ? i*dp[i-1][j+1][k] : 0;
   				dp[i][j][k] = (a+b+c+n)/(i+j+k);
   			}
   		}
   	}
   	cout<<fixed<<setprecision(10);
	cout<<dp[c3][c2][c1]<<endl;   	
	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n;
    cin >> n;

    string s;
    cin >> s;

    int l = 0, r = 0;
    for(auto is:s) {
        if(is=='(') r++;
        else {
            if(r==0) l++;
            else r--;
        }
    }

    for(int il=0;il<l;il++) cout << '(';
    cout << s;
    for(int ir=0;ir<r;ir++) cout << ')';
    return 0; 
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e8;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl



int main(void)
{
	int h, w;
	int H, W;

	cin >> H >> W;
	cin >> h >> w;

	if(h>w)
	cout << (H*W) - (h*W+(H-h)*w)<< endl;
	else
		cout << (H*W) - (w*H + (W - w)*h) << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <numeric>
#include <iostream>
#include <vector>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
 
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int m, n;
	cin >> m >> n;
 
	vector<long long> p(m + 1, 0);
	rep(i, m) {
		cin >> p[i + 1];
	}

	sort(p.begin() + 1, p.end(), greater<long long>());
	partial_sum(ALL(p), p.begin());
 
	vector<long long> dp(m + 1, 0);
	rep(j, n) {
		int c, e;
		cin >> c >> e;
 
		for(int i = m - 1; i >= 0; --i) {
			const int next = min(m, i + c);
			chmax(dp[next], dp[i] + p[next] - p[i] - e);
		}
	}
 
	cout << *max_element(ALL(dp)) << endl;
 
	return EXIT_SUCCESS;
}

Measured memory_bytes: 1352
n, k = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * (1 + 10 ** 5)
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[n-1])

Measured memory_bytes: 55392
#include<bits/stdc++.h>
//this code is written by Itst
using namespace std;

#define int long long

const int MOD = 1e9 + 7 , _ = 1e5 + 7;
vector < int > ch[_];
int ans = 1 , N , K , jc[_] , inv[_];

int poww(int a , int b){
	int times = 1;
	while(b){
		if(b & 1) times = times * a % MOD;
		a = a * a % MOD; b >>= 1;
	}
	return times;
}

int P(int a , int b){return a < b ? 0 : jc[a] * inv[a - b] % MOD;}

void dfs(int x , int p){
	if(x == 1)
		ans = ans * P(K - 1 , ch[x].size()) % MOD;
	else
		ans = ans * P(K - 2 , ch[x].size() - 1) % MOD;
	for(auto t : ch[x])
		if(t != p) dfs(t , x);
}

signed main(){
	cin >> N >> K;
	if(K == 1){puts(N == 1 ? "1" : "0"); return 0;}
	jc[0] = 1;
	for(int i = 1 ; i <= 1e5 ; ++i)
		jc[i] = 1ll * jc[i - 1] * i % MOD;
	inv[100000] = poww(jc[100000] , MOD - 2);
	for(int i = 1e5 - 1 ; i >= 0 ; --i)
		inv[i] = inv[i + 1] * (i + 1ll) % MOD;
	for(int i = 1 ; i < N ; ++i){
		int a , b; cin >> a >> b;
		ch[a].push_back(b); ch[b].push_back(a);
	}
	dfs(1 , 0);
	printf("%lld\n" , ans * K % MOD);
	return 0;
}


Measured memory_bytes: 10752
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
int main() 
{
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s1;
  int n,c = 0;
  cin >> n;
  cin >> s1;
  for (int i = 0; i < n-2; ++i)
  {
    if(s1[i] == 'A' && s1[i+1] == 'B' && s1[i+2] == 'C')
    {
      c++;
      i+=2;
    }
  }
  cout << c;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <cstdlib>

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

const ll MOD = 1e9+7;

static long gcd(long a, long b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
/*
long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}*/

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

map< ll, ll > prime_factor(ll n) {//素因数分解
    map< ll, ll > ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

ll calcNumOfCombination(ll n, ll r){
    ll num = 1;
    for(ll i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}

int bubblesort(vector<int> array,int size){//バブルソート　転倒数
    int kaisu = 0;
    for(int i = 0; i < size; i++){
        for(int j = i + 1; j < size; j++){
            if(array[i] > array[j]){
                int number = array[i];
                array[i] = array[j];
                array[j] = number;
                kaisu++;
            }
        }
    }
    return kaisu;
}

ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum = (sum * i)%MOD;
    }
    return sum;
}

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

        }
    }


    cout << result << endl;


}






Measured memory_bytes: 384
#include<stdio.h>

int F[50];
int fibonacci(int);

main(){

  int n,c,i;

  scanf("%d",&n);
  c= fibonacci(n);
  printf("%d\n",c);

  return 0;
}


int fibonacci(int n){
  int i;
  F[0]=1;
  F[1]=1;
  for(i=2;i<=n;i++){
    F[i]= F[i-2]+F[i-1];
  }
  return F[n];
}

Measured memory_bytes: 596
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: Bytes,
        t: Bytes,
    }
    let mut ok: bool = true;
    for i in 0..s.len() {
        if s[i] != t[i] {
            ok = false;
        }
    }
    let ans: &str = {
        if ok {
            "Yes"
        } else {
            "No"
        }
    };
    println!("{}", ans);
}


Measured memory_bytes: 2180
/* ***************************************************
 *	Author        :mutinner
 *	Created Time  :Sat 01 Sep 2018 08:59:41 PM CST
 *	File Name     :20:59:41.cpp
 *************************************************** */

#include <bits/stdc++.h>
using namespace std;

int main() {
	int x1, y1, x2, y2;
	while ( cin >> x1 >> y1 >> x2 >> y2 ) {
		cout << x2 - y2 + y1 << ' ' << y2 + x2 - x1 << ' ' << x1 -y2 + y1 << ' ' << y1 + x2 - x1 << endl;
	}
	return 0;
}


Measured memory_bytes: 384
N=gets.to_i
s=gets.chomp.chars
cnt=0
s.each_with_index do |el,i|
  if (el === "A") && (i <= s.size-2)
    if (s[i+1] == "B") && (s[i+2] == "C")
      cnt+=1
    end
  end
end
puts cnt

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

using namespace std;

int main (){
	
	int a,c,ma = -1000000,mi = 1000000;
         long long int sum = 0;
	cin >> a;
	for(int b = 0;b < a;b++){
		cin >> c;
		ma = max(ma,c);
		mi = min(mi,c);
		sum += c;
	}
	cout << mi<<" " << ma <<" "<< sum << endl;
return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  //
  
  long long ans = -1000000000000000001;

  ans = max(ans, A*C);
  ans = max(ans, A*D);
  ans = max(ans, B*C);
  ans = max(ans, B*D);
    cout<<ans<<endl;
 

  return 0;
}


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


int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  string S;
  cin >> S;
  
  int countAB = 0;
  int countB = 0;
  
  for (int i=0; i<N;i++){
    if(S.at(i) =='c'){
      cout << "No" << endl;
    }
    else if(S.at(i) =='a'){
      if(countAB<A+B){
        cout << "Yes" << endl;
        countAB = countAB + 1;
      }
      else {
        cout << "No" << endl;
      }
    }
    else if(S.at(i) =='b'){
      if(countB<B && countAB<A+B){
        cout << "Yes" << endl;
        countAB = countAB + 1;
        countB = countB + 1;
      }
      else{
        cout << "No" << endl;
      }
    }
  } 
      
  return 0;
}



Measured memory_bytes: 3748
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/24 16:28:48 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

// TOP
void	Main()
{
	int	n, minx, maxx, miny, maxy;
	minx = 0;
	miny = 0;
	cin >> maxx >> maxy >> n;
	rep(i, n)
	{
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1)
			minx = max(minx, x);
		if (a == 2)
			maxx = min(maxx, x);
		if (a == 3)
			miny = max(miny, y);
		if (a == 4)
			maxy = min(maxy, y);
	}
	if (minx >= maxx || miny >= maxy)
	{
		cout << 0 << endl;
		return ;
	}
	cout << (maxx - minx) * (maxy - miny) << endl;
}
// END

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


Measured memory_bytes: 256
import math

r = 999999
sqrt = int(math.sqrt(r))
p = [1 for i in range(r)]
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    try:
        n = int(raw_input())
        print sum(p[:n])
    except:
        break

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

public class Main {
	static final char[] END_OF_INPUT = "END OF INPUT".toCharArray();

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNextLine()) {
			char[] line = in.nextLine().toCharArray();
			if (!Arrays.equals(line, END_OF_INPUT)) {
				int num = 0;
				for (char c : line) {
					if (c == ' ') {
						System.out.print(num);
						num = 0;
					} else {
						num++;
					}
				}
				System.out.println(num);
			}

		}

	}
}

Measured memory_bytes: 17324
import java.util.*;
import java.math.*;

public class Main {
  private static final int MOD = 1000000007;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    String[] a = new String[H];
    for (int i = 0; i < H; i++)
      a[i] = sc.next();
    sc.close();

    int[][] dp = new int[H][W];
    dp[0][0] = 1;
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        if (dp[y][x] != 0 || a[y].charAt(x) == '#') continue;
        dp[y][x] = (
            (0 < y ? dp[y - 1][x] : 0)
            + (0 < x ? dp[y][x - 1] : 0)
            ) % MOD;
      }
    }

    long ans = dp[H - 1][W - 1];
    System.out.println(ans);
  }
}

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

#ifndef errOut
#define errOut(s)
#endif

using Count = int;
using Candies = std::array<std::vector<Count>, 2>;

Count calc(Candies& candies, int n) {
    Count  ret = 0;
    for (int downColumn = 0; downColumn < n; ++downColumn) {
        Count cnt = 0;
        int row = 0;
        for(int column = 0;column < n; ++column) {
            cnt += candies[row][column];
            if (column == downColumn) {
                ++row;
                cnt += candies[row][column];
            }
        }
        ret = std::max(ret, cnt);
    }
    return ret;
}

int main() {
    int n;
    std::cin >> n;
    Candies candies;
    for (int row = 0; row < 2; ++row) {
        candies[row].reserve(n);
        for(int column = 0; column < n; ++column) {
            std::cin >> candies[row][column];
        }
    }
    auto ret = calc(candies, n);
    std::cout << ret << std::endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
import datetime
import itertools
import sys

# 入力
#N = int(input())
#S = str(input())
#N, A, B = map(int, input().split())

N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [sys.maxsize for _ in range(N+K)]

#print (dp)
dp[0] = 0
for i in range(N) :
  for ki in range(1, K+1) :
    if i+ki > N-1 :
      break
    else :
      dp[i+ki] = min(abs(h[i]-h[i+ki]) + dp[i], dp[i+ki])

print (dp[N-1])



Measured memory_bytes: 69480
sx, sy, tx, ty = map(int, input().split())
ans = "R" * (tx-sx) + "U" * (ty-sy) + "L" * (tx-sx) + "D" * (ty-sy)
ans += "D" + "R" * (tx-sx + 1) + "U" * (ty-sy + 1) + "L"
ans += "U" + "L" * (tx - sx + 1) + "D" * (ty - sy + 1)  + "R" 
print(ans)

Measured memory_bytes: 3060
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, p;
  cin >> n >> p;
  string s_;
  cin >> s_;
  vll s(n);
  rep(i, n) s[i] = s_[i] - '0';
  ll ans = 0;
  if(p == 2){
    rep(i, n){
      if(s[i]%2 == 0){
        ans += i+1;
      }
    }
  }else if(p == 5){
    rep(i, n){
      if(s[i]%5 == 0){
        ans += i+1;
      }
    }
  }else{
    map<ll, ll> cnt;
    cnt[0]++;
    ll c = 1;
    ll cur = 0;
    repb(i, n){
      cur += c * s[i];
      cur %= p;
      cnt[cur]++;
      c *= 10;
      c %= p;
    }
    dump(cnt);
    for(auto&& e: cnt){
      ans += e.second*(e.second-1)/2;
    }
  }
  print(ans);
}


Measured memory_bytes: 2580
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

int main()
{
    string s;
    int d;
    cin >> s >> d;
    int n = s.size();

    vector<vector<int> > dp(2, vector<int>(d, 0));
    dp[0][0] = 1;
    for(int i=0; i<n; ++i){
        vector<vector<int> > nextDp(2, vector<int>(d, 0));
        for(int x=0; x<2; ++x){
            for(int y=0; y<d; ++y){
                for(int a=0; a<=9; ++a){
                    if(x == 0 && s[i] - '0' < a)
                        continue;

                    int x2 = x;
                    if(a < s[i] - '0')
                        x2 = 1;
                    int y2 = (y + a) % d;
                    nextDp[x2][y2] += dp[x][y];
                    nextDp[x2][y2] %= MOD;
                }
            }
        }
        dp = move(nextDp);
    }

    int ans = (dp[0][0] + dp[1][0] - 1LL + MOD) % MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
 
void b_contest_with_drinks_easy(void) {
	int n, m;
	int sum = 0;
	int t[110];
	int p[110];
	int x[110];
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
		sum += t[i];
	}
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> p[i] >> x[i];
	}
 
	int sub = 0;
	for (int i = 1; i <= m; i++) {
		sub = t[p[i]] - x[i];
		cout << sum - sub << endl;
	}
}
 
int main()
{
	b_contest_with_drinks_easy();
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	long long n;
	cin >> n;

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

	int cnt = 1;
	int ans = 0;
	int flag = 0;
	for (int i = 0;i < n;i++) {
		if (a[i] == cnt) {
			cnt++;
		}
		else {
			ans++;
		}
	}

	if (cnt == 1) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

int main(){
//    freopen("date.in", "r", stdin);
//    freopen("date.out", "w", stdout);
    int n; cin >> n;
    long long s = n/500*1000;
    n = n%500;
    s += n/5*5;
    cout << s;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a = [0] + a +[0]
s = 0

for i in range(1,n+2):
    s += abs(a[i]-a[i-1])

for i in range(1,n+1):
    print(s-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))

Measured memory_bytes: 14048
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;


int main(){
    int n;
    cin >> n;
    using P = pair<ll, ll>;
    priority_queue<P, vector<P>, greater<P>> que;
    rep(i, n){
        ll x, l;
        cin >> x >> l;
        que.push({x+l, x-l});
    }

    int ans = 0;
    ll now = -INF;
    while(que.size() != 0){
        P p = que.top();
        que.pop();
        ll r = p.first, l = p.second;
        if(now <= l){
            ans++;
            now = r;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

struct Bipartite_matching{
	int V;
	vector< vector<int> > G;
	vector<int> match;
	vector<bool> used;
	void init(int N){
		V=N;
		G.assign(V,vector<int>());
		match.assign(V,0);
		used.assign(V,false);
	}
	void add_edge(int v,int u){
		G[v].pb(u);
		G[u].pb(v);
	}
	bool dfs(int v){
		used[v]=true;
		rep(i,G[v].size()){
			int u=G[v][i],w=match[u];
			if(w<0 || (!used[w] && dfs(w))){
				match[v]=u;
				match[u]=v;
				return true;
			}
		}
		return false;
	}
	int max_matching(){
		int res=0;
		fill(all(match),-1);
		rep(v,V){
			if(match[v]<0){
				fill(all(used),false);
				if(dfs(v)) res++;
			}
		}
		return res;
	}
};

bool isprime(int x){
	if(x<=2) return 0;
	for(int i=2;i*i<=x;i++){
		if(x%i==0) return 0;
	}
	return 1;
}

int main(){
	int N;
	cin>>N;
	map<int,int> mp;
	rep(i,N){
		int x;
		cin>>x;
		mp[x]++;
		mp[x-1]++;
	}
	vector<int> vs;
	for(pair<int,int> p:mp){
		if(p.sc!=2) vs.pb(p.fs);
	}
	int K = vs.size();
	Bipartite_matching bip;
	bip.init(K);
	rep(i,K) rep(j,i){
		int d = vs[i]-vs[j];
		if(isprime(d)) bip.add_edge(i,j);
	}
	int o = 0;
	rep(i,K) if(vs[i]%2==0) o++;
	int m = bip.max_matching();
	if((o-m)%2==1) m--;
	cout<<K-m<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
   int t = 1;
 //  cin >> t;
    
    while(t--)
    {
       
        int n,i,j;
    
       string s;
        cin >> s;
        if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
            cout << 3;
        else if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R'))
            cout << 2;
        else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
            cout << 1;
        else
            cout << 0;
            
        
        cout << '\n';
    }
    
        
      
        
}


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

int main() {
  int r,g,b,t;
  
  cin >> r >> g >> b;
  
  t=r*100+g*10+b;
  if(t%4==0) cout << "YES"<<endl;
  else cout << "NO" << endl;
  return 0;
}
  
  

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

using namespace std;

int main(){
  int n ,r;
  while (cin >> n >> r){
    if (n == 0 && r == 0){
      return 0;
    }
    stack<int> cards;

    for (int i=0; i<n; ++i){
      cards.push(i+1);
    }
    
    for (int i=0; i<r; ++i){
      int p, c;
      cin >> p >> c;//上からP枚目からC枚とってシャッフル
      int *tmp1 = new int[p-1];
      for (int i=(p-2); 0<=i; --i){
	tmp1[i] = cards.top();
	cards.pop();
      }
      int *tmp2 = new int[c];
      for (int i=(c-1); 0<=i; --i){
	tmp2[i] = cards.top();
	cards.pop();
      }
      for (int i=0; i<(p-1); ++i){
	cards.push(tmp1[i]);
      }
      for (int i=0; i<c; ++i){
	cards.push(tmp2[i]);
      }
      delete[] tmp1;
      delete[] tmp2;      
    }
    cout << cards.top() << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
import kotlin.math.*

fun main(args: Array<String>) {
    val (a, b, h, m) = readLine()!!.split(" ").map(String::toInt)

    val degH = h * 30 + m * 0.5
    val degM = m * 6;
    val diff = min(abs(degH - degM), abs(degM - degH + 360))

    println(sqrt((a * a) + (b * b) - (2 * a * b * cos(diff.toDouble() * PI / 180))))
}


Measured memory_bytes: 36580
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long n,m,k=1;
	cin>>n>>m;
	if(m<n*n){
	for(int i=0;i<m/n;i++){
		if(m%(i+1)==0)k=(i+1);
	}
	cout<<k<<endl;
	}
	else{
		int j=n;
		while(m%j!=0)j++;
	cout<<m/j<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>

using namespace std;
using ll = long long;

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

	for (int i = 0; i < S.size(); ++i) {
		int index = S[i] - 'A' + N;
		index %= 26;
		S[i] = 'A' + index;
	}

	cout << S << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int a[3][3], b, c[3][3], i, j, k, n, bingo = 0;
    
    for(i = 0;i < 3;i++){
        scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
    }    
    scanf("%d", &n);

    for(i = 0;i < 3;i++){
        for(j = 0;j < 3;j++){
            c[i][j] = 0;
        }
    }

    for(i = 0;i < n; i++){
        scanf("%d", &b);
        for(j = 0;j < 3;j++){
            for(k = 0;k < 3;k++){
                if(a[j][k] == b){
                    c[j][k] = 1;
                }
            }
        }
    }

    for(i = 0;i < 3;i++){
        if(c[i][0] + c[i][1] + c[i][2] == 3) bingo = 1;
        else if(c[0][i] + c[1][i] + c[2][i] == 3) bingo = 1;
    }
    if(c[0][0] + c[1][1] + c[2][2] == 3) bingo = 1;
    if(c[2][0] + c[1][1] + c[0][2] == 3) bingo = 1;

    if(bingo == 1) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int (i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int (i) = (int)(initial); (i) < (int)(n); ++(i))
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int (i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int (i) = (int)(initial); (i) > (int)(n); (i)--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
	vector< pair<ll, ll> > p;
	for(ll i = 2; i*i <= n; i++) {
		if ((n % i) != 0) continue;
		p.push_back(make_pair(i, 0));
		while((n % i) == 0) {
			n /= i;
			p[i].second += 1;
		}
		p.push_back(make_pair(n, 0));
	}

	if (n != 1) p.push_back(make_pair(n, 1));
	return p;
}

int main() {
	ll N, M;
	cin >> N >> M;

	if (N == 1 && M == 1) {
		cout << 1 << endl;
		return 0;
	}

	if (N == 1) {
		cout << (M-2) << endl;
		return 0;
	}

	if (M == 1) {
		cout << (N-2) << endl;
		return 0;
	}
	
	if (N == 2 || M == 2) {
		cout << 0 << endl;
		return 0;
	} 

	cout << ((N-2) * (M-2)) << endl;
	return 0;
}

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

#define int long long
#define MAX 55

int K;
int ans[MAX];

signed  main(){

  cin>>K;

  cout<<50<<endl;

  for(int i = 0; i < 50; i++){
    ans[i] += i+K/50;
    if(49-i < K%50) ans[i]++;
  }
  for(int i = 0; i < 50; i++){
    if(i)cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;

  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    if (N == 1) {
        cout << "Hello World" << endl;
    } else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    g = LIR(n)
    if n&1:
        g.sort()
        l = g[n>>1][0]
        g.sort(key = lambda x:x[1])
        r = g[n>>1][1]
        print(r-l+1)
    else:
        g.sort()
        l = g[(n>>1)-1][0]+g[(n>>1)][0]
        g.sort(key = lambda x:x[1])
        r = g[n>>1][1]+g[(n>>1)-1][1]
        print(r-l+1)
    # ans = set()
    # # for i in range(g[0][0],g[0][1]+1):
    # #     for j in range(g[1][0],g[1][1]+1):
    # #         for k in range(g[2][0],g[2][1]+1):
    # #             p = [i,j,k]
    # #             p.sort()
    # #             ans.add(p[1])
    # for i in range(g[0][0],g[0][1]+1):
    #     for j in range(g[1][0],g[1][1]+1):
    #         ans.add((i+j)/2)
    # ans = list(ans)
    # ans.sort()
    # print(len(ans))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 110880
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    long long ans = n * (n - 1LL) / 2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.WriteLine("! "+sb.ToString());
    }
    void Calc(){
        long count = 10000000000;
        int digit = 0;
        while(true){
            Console.WriteLine("? "+ count);
            string s = Console.ReadLine();
            if(s[0] == 'Y'){
                break;
            }
            else{
                count /= 10;
            }
            digit++;
        }
        string ans = "";
        if(digit == 0){
            long C = 9;
            ans += "1";
            while(true){
                Console.WriteLine("? "+C);
                C = C*10+9;
                string s = Console.ReadLine();
                if(s[0] == 'Y'){
                    break;
                }
                ans += "0";
            }
        }
        else{
            long bf = count+1;
            long bl = count*10-1;
            while(bf != bl){
                long bc = (bf+bl)/2;
                Console.WriteLine("? "+ bc*10);
                string s = Console.ReadLine();
                if(s[0] == 'Y'){
                    bl = bc;
                }
                else{
                    bf = bc+1;
                }
            }
            ans += bf;
        }
        sb.Append(ans);
    }
}

Measured memory_bytes: 13480
#include<iostream>
#include<algorithm>
#include<vector>
#include <numeric>
using namespace std;
int main(int argc, char const *argv[]) {
    long long N;
    int K;
    std::cin >> N >> K;
    if(N%2==1){
        if(N/2+1>=K){
            std::cout << "YES" << '\n';
        }else{
            std::cout << "NO" << '\n';
        }
    }else{
        if(N/2>=K){
            std::cout << "YES" << '\n';
        }else{
            std::cout << "NO" << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int R[100];
    int in[100];
    int n, j, m, l, i;

    m =0;
    l =0;

    for (i=0; i<100; i++){
        R[i] = 0;
    }

    i=0;
    while ((scanf("%d", &in[i]))!=EOF){
        i++;
        if (i==99) break;
    }

    R[0] = in[0];

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


        if (in[k] == 0) {
            for ( j=0; j<100; j++){
                if (R[j] == 0) break;
            }
            printf("%d\n", R[j-1]);
            R[j-1] = 0;
        }else{
            for (j=0; j<100; j++){
                if (R[j] == 0) break;
            }
            R[j] = in[k];
        }


        if (R[0] == 0) break;

    }

    return 0;
}



Measured memory_bytes: 2104
# D問題
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# nCr
def nCr(n,r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def main():
  n,k=LI()

  # 隙間
  a=n-k+1

  for i in range(1,k+1):
    if a<i or k-1<i-1:
      print(0)
    else:
      print(nCr(a,i)*nCr(k-1,i-1)%mod)

main()


Measured memory_bytes: 88276
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

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

    vector<int> c(N), t(N);
    for (int i = 0; i < N; ++i)
        cin >> c[i] >> t[i];

    int i_min = -1;
    for (int i = 0; i < N; ++i)
    {
        if (t[i] > T)
            continue;
        else if (i_min < 0 or c[i] < c[i_min])
            i_min = i;
    }

    if (i_min >= 0)
        cout << c[i_min] << endl;
    else
        cout << "TLE" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
#define brep1(i,n) for(int i=n;i>=1;i--)
#define rep1(i,n) for(int i=1;i<n;i++)
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
#define ll long long


int main(void){
    int n;
    cin >> n;
    vector<pair<int,int>> a;
    rep(i,n){
        int w,h;
        scanf("%d %d", &w,&h);
        a.emplace_back(h,w);
    }
    sort(a.begin(),a.end());
    ll tim = 0;
    rep(i,n){
        tim += a[i].second;
        if(tim > a[i].first){
            cN;
            return 0;
        }
    }
    cY;
    return 0;
}



Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
int n;
vector<int>a;
int check(int x){
    ll sum = 0;
    rep(i,x+1)sum += a[i];
    for(int i = x+1; i < n; i++){
        if(2*sum>=a[i])sum += a[i];
        else{
            return 0;
        }
    }
    return 1;
}
int main(){
    cin >> n;
    a.resize(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    int l = -1;
    int r = n-1;
    while(r-l>1){
        int mid = (l+r)/2;
        // cerr << mid <<" " << check(mid) << endl;
        if(check(mid)){
            r = mid;
        }else{
            l = mid;
        }
    }
    // cerr << l << " " << r << endl;
    cout << n-r << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int x=scan.nextInt();
boolean a=true;
for(int i=1; i<x+1; i++){
   if(i%3==0){
      System.out.print(" "+i);
      a=false;
   }
   int n=i; 
   while(a){
      if(n%10==3){
         System.out.print(" "+i);
         a=false;
      }else if(n>10){
         n =n/10;
      }else  a=false;
   }
   a=true;
}
System.out.println();
}
} 

Measured memory_bytes: 28736
import sys
readline = sys.stdin.readline
X, Y, Z, K = map(int, readline().split())
A = sorted(list(map(int, readline().split())), reverse=True)
B = sorted(list(map(int, readline().split())), reverse=True)
C = sorted(list(map(int, readline().split())), reverse=True)

ABC = []
for a in range(X):
    for b in range(Y):
        if (a+1)*(b+1) > K:
            break
        for c in range(Z):
            if (a+1)*(b+1)*(c+1) > K:
                break
            ABC.append(A[a] + B[b] + C[c])
            
for ai in sorted(ABC, reverse=True)[:K]:
    print(ai)


Measured memory_bytes: 46064