akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

#define MAX 200

//char型をint型に変換し、seisuに返す
int Ihenkan(char stack[][MAX][MAX], int n)
{
	int kariseisu;

	kariseisu = atoi(stack[0][n]);

	return kariseisu;
}

//計算用関数
int keisan(char enz[], int seisu[], int Scount, int Ecount)
{
	int i = Scount - 1;

	
			switch (enz[Ecount]) {
			case '+':
				seisu[i - 1] = seisu[i - 1] + seisu[i];
				break;

			case '-':
				seisu[i - 1] = seisu[i - 1] - seisu[i];
				break;

			case '*':
				seisu[i - 1] = seisu[i - 1] * seisu[i];
				break;
			}

	return seisu[i - 1];
}

int main(void)
{
	int i = 0, j = 0, k = 0, n = 0, c = 0;
	char stack[MAX][MAX];
	int seisu[MAX];
	char enz[MAX];
	int Ecount = 0, answer = 0, Scount = 0;


	// スタックの計算式をため、演算子と整数で分けてカウントする
	while(1){

		scanf("%c", &stack[n][i]);

		if (stack[n][i] == '\n') {
			break;
		}

		if ((stack[n][i] >= '0') && (stack[n][i] <= '9')) {
			seisu[j] = Ihenkan(stack, n);
			i++;
		}
		
		else {
			if (stack[n][i] == ' ') {
				if ((stack[n][i - 1] >= '0') && (stack[n][i - 1] <= '9')) {
					Scount++;
					j++;
					i = 0;
				}
				n++;
				
				continue;
			}

			enz[k] = stack[n][i];
			seisu[j - 2] = keisan(enz, seisu, Scount, Ecount);
			k++;
			j--;
			Scount--;
			Ecount++; 
			}
		}
		
	answer = seisu[j - 1];

	printf("%d\n", answer);

	return 0;	

}


Measured memory_bytes: 2100
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    d = II()
    print("Christmas",end="")
    for _ in range(25 - d):
        print(" Eve", end="")
    print()
    return

#B
def B():
    n = II()
    p = IR(n)
    p.sort()
    print(sum(p) - p[-1] // 2)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 38512
S = gets.chomp
Q = gets.to_i
is_positive = true
out = S.chars

front = []
back = []
Q.times do |i|
  query = gets.split
  if query[0] == "1"
    is_positive = !is_positive
  else
    f = query[1]
    c = query[2]
    if is_positive
      if f == "1"
        out.unshift(c)
      else
        out.push(c)
      end
    else
      if f == "1"
        out.push(c)
      else
        out.unshift(c)
      end
    end
  end
end
if is_positive
	puts out.join
else
  	puts out.reverse.join
end


Measured memory_bytes: 30332
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    
    int aa=0;
    int i=max(a,b);
    while(true){
        if(a%i==0&&b%i==0){
            aa++;
        }
        if(aa==c){
            cout<<i<<endl;return 0;
        }
        
        i--;
    }
    
return 0;
}


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

int main(){
 //Takahashi a=hp
  float hp_t, s_t, hp_a, s_a;
  cin >> hp_t >> s_t >> hp_a >> s_a;
  //takahashi > aoki
  int dmg_t = ceil(hp_t / s_a);
  int dmg_a = ceil(hp_a / s_t);
  //cout << hp_t / s_a << " " << hp_a / s_t;
  
  if(dmg_t > dmg_a){
   	 cout << "Yes" << endl;
  }else if(dmg_t == dmg_a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

// Unionfind
struct UF {
	vector<int> p;
	UF() = default;
	explicit UF(int n) : p(n + 1, -1) { p.back() = n; }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (p[x] > p[y]) swap(x, y);
		p[x] += p[y];
		p[y] = x;
		p.back()--;
		return true;
	}
	int find(int x) { return (p[x] < 0 ? x : p[x] = find(p[x])); }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -p[find(x)]; }
	int count() { return p.back(); }
};

void _main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(N), pos(N);
    REP (i, N) {
        cin >> p[i];
        p[i]--;
        pos[p[i]] = i;
    }
    UF uf(N);
    REP (i, M) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }
    int ans = 0;
    REP (i, N) ans += uf.same(pos[i], i);
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 5480
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

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


inline long long modo(long long a, long long m) {
    return (a % m + m) % m;
}

long long extGcd(long long a, long long b, long long &p, long long &q) {  
    if (b == 0) { p = 1; q = 0; return a; }  
    long long d = extGcd(b, a%b, q, p);  
    q -= a/b * p;  
    return d;  
}

pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
  long long p, q;
  long long d = extGcd(m1, m2, p, q);
  if ((b2 - b1) % d != 0) return make_pair(0, -1);
  long long m = m1 * (m2/d);
  long long tmp = (b2 - b1) / d * p % (m2/d);
  long long r = modo(b1 + m1 * tmp, m);
  return make_pair(r, m);
}


int main() {
    ll n;
    cin >> n;
    vector<ll> d;
    for(auto x : prime_factor(2*n)){
        d.push_back(pow(x.first, x.second));
    }
    int s = d.size();
    ll ans = inf;
    rep(bit, (1<<s)){
        ll m1 = 1, m2 = 1;
        rep(i, s){
            if(bit & (1<<i)) m1 *= d[i];
            else m2 *= d[i];
        }
        pair<ll, ll> p = ChineseRem(m1-1, m1, 0, m2);
        if(p.first != 0)chmin(ans, p.first);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4052
import java.util.*;
public class Main{
	public static final Scanner sc = new Scanner(System.in);
  	public static void main(String[] arg){
		String s = sc.next();
		long k = sc.nextLong();
        char c;
        char ans = '1';
        for (int i = 0; i<s.length(); i++){
        	c = s.charAt(i);
            if (ans != c){
            	ans = c;
                break;
            }
            k--;
            if (k==0){
            	break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35652
#include<iostream>
#include<stack>
#include<cstdlib>
using namespace std;

int main()
{
    stack<int> S;
    string s;
    while(cin >> s)
    {
        if(s[0] == '+' || s[0] == '-' || s[0] == '*')
        {
            int a = S.top();
            S.pop();
            int b = S.top();
            S.pop();
            switch(s[0])
            {
                case '+':
                    S.push(a + b);
                    break;
                case '-':
                    S.push(b - a);
                    break;
                case '*':
                    S.push(a * b);
                    break;
            }
        }
        else
            S.push(atoi(s.c_str()));
        char c[2];
        cin.get(c, 2);
        if(c[0] == '\n')
            break;
    }
    cout << S.top() << endl;
    return 0;
}



Measured memory_bytes: 3188
n, m, l = map(int,input().split())
a = []
e = []
for i in range(n):
    b = list(map(int,input().split()))
    a.append(b)
for i in range(m):
    d = list(map(int,input().split()))
    e.append(d)
for i in range(n):
    for j in range(l):
        f = 0
        for o in range(m):
            f += (a[i][o]*e[o][j])
        print(f,end='')
        if j != l-1:
            print(' ',end='')
    print()


Measured memory_bytes: 6512
a=[0]*5
for i in range(5):
    a[i]=int(input())
ha=10
for i in range(5):
    if a[i]%10!=0:
        ha=min(ha,a[i]%10)
ans=0
for i in range(5):
    if a[i]%10==0:
        ans+=a[i]
    else:
        ans+=a[i]+(10-a[i]%10)
print(ans-(10-ha))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
     
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define double long double
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
#define mod2 998244353  
#define pi 3.14159265358979323846 

int solve(){
    int n;
    string s;
    cin>>s;
    if(s.size()>5&&s[2]==s[3]&&s[4]==s[5]) cout<<"Yes";
    else cout<<"No";
    return 0;
}   
     
signed main(){
    IOS;
    //freopen("input.txt", "r" , stdin);
    //freopen("output4.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
      // cout<<" * "<<t<<"\n";
    }
//    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<bitset>
using namespace std ;
using ll = long long ;

int main(){
	ll n ; cin >> n ;
	vector<vector<pair<ll,ll>>> com(n,vector<pair<ll,ll>>(0)) ;
	for(int i=0;i<n;i++){
		int a ; cin >> a ;
		for(int j=0;j<a;j++){
			int x,y ;
			cin >> x >> y ;
			com.at(i).push_back(make_pair(x,y)) ;
		}
	}
	ll ans = 0 ;
	for(int i=0;i<(1<<n);i++){
		bitset<20> b(i) ;
		bool ok = true ;
		for(int j=0;j<n;j++){
			if(b[j]){
				for(int k=0;k<com.at(j).size();k++){
					if(b[com.at(j).at(k).first-1]!=com.at(j).at(k).second){
						ok = false ;
						break ;
					}
				}
			}
			if(!ok) break ;
		}
		if(ok&&ans<b.count()) ans = b.count() ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
s = input()
length_s = len(s)
paper_cnt = 0
ans = 0

for i in range(length_s):
    if s[i] == 'g':
        if paper_cnt < 0:
            ans += 1
            paper_cnt += 1

        else:
            paper_cnt -= 1

    else:
        if paper_cnt < 0:
            paper_cnt += 1

        else:
            ans -= 1
            paper_cnt -= 1

print(ans)


Measured memory_bytes: 9232
import sys
import numpy as np
N, W = map(int, input().split())
it = iter(map(int, sys.stdin.read().split()))
dp = np.full(N * 1000 + 1, W + 1, dtype=np.int64)
dp[0] = 0
for w, v in zip(it, it):
    np.minimum(dp[:-v] + w, dp[v:], out=dp[v:])
print(((dp <= W) * np.arange(N * 1000 + 1)).max())

Measured memory_bytes: 14904
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
X = []
for i in range(0, Q):
    X.append(list(map(int, input().split())))
sample = list(combinations_with_replacement(range(1, M+1), N))
ans = 0
for s in sample:
    tmp = 0
    for x in X:
        if s[x[1]-1]-s[x[0]-1] == x[2]:
            tmp += x[3]
    ans = max(tmp, ans)
print(ans)


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

using namespace std;

int main(void) {
	int N,M;
	cin >> N >> M;
	vector<int> city(N,0);
	int temp;
	for (int i = 0; i < 2*M; ++i) {
		cin >> temp;
		++city[temp-1];
	}
	for (int i = 0; i < N; ++i) {
		cout << city[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2000+10;
const int inf=0x3f3f3f3f;
struct Edge {
	int from,to,nxt;
}e[maxn<<1];
int n,m;
int tot,ans,Ans=inf;
int head[maxn];

inline void file() {
	freopen("AGC001C.in","r",stdin);
	freopen("AGC001C.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

inline void add(int from,int to) {
	e[++tot]=(Edge){from,to,head[from]}; head[from]=tot;
	e[++tot]=(Edge){to,from,head[to]}; head[to]=tot;
}

void dfs(int u,int fa,int deep,int D) {
	if (deep>D) ++ans;
	for (int i=head[u];i!=0;i=e[i].nxt) {
		int v=e[i].to;
		if (v==fa) continue;
		dfs(v,u,deep+1,D);
	}
}

int main() {
//	file();
	n=read(); m=read();
	For (i,1,n-1) {
		int x=read(),y=read(); add(x,y);
	}
	if (m&1) {
		for (int i=1;i<=tot;i+=2) {
			if (m&1) {
				ans=0;
				dfs(e[i].from,e[i].to,0,m/2); dfs(e[i].to,e[i].from,0,m/2);
				chkmin(Ans,ans);
			}
		}
	}
	else {
		For (i,1,n) {
			ans=0;
			dfs(i,0,0,m/2);
			chkmin(Ans,ans);
		}
	}
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	char[] ch=sc.next().toCharArray();
    for(int i=0;i<ch.length;i++){
      ch[i]='x';
      System.out.print(ch[i]);
    }
  }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  vector<pair<char, char> > ku{
    {'.', '.'}, {'.', '#'}, {'#', '.'}, {'#', '#'}
  };
  int n; cin >> n;
  string s1 = "", s2 = "";
  bool nx = false;
  while (!nx && s1.length() < n) {
    REP(i, 4) {
      s1 += ku[i].first;
      s2 += ku[i].second;
      cout << s1 << '\n' << s2 << endl;
      string r; cin >> r;
      if (r == "F") {
        s1.pop_back();
        s2.pop_back();
      } else if (r == "T") {
        break;
      } else if (r == "end") {
        return 0;
      }
      if (i + 1 == 4) {
        nx = true;
        break;
      }
    }
  }
  while (s1.length() < n) {
    REP(i, 4) {
      s1.insert(s1.begin(), ku[i].first);
      s2.insert(s2.begin(), ku[i].second);
      cout << s1 << '\n' << s2 << endl;
      string r; cin >> r;
      if (r == "F") {
        s1.erase(s1.begin());
        s2.erase(s2.begin());
      } else if (r == "T") {
        break;
      } else if (r == "end") {
        return 0;
      }
      if (i + 1 == 4) break;
    }
  }
  assert(false);
}


Measured memory_bytes: 724
n, k = map(int, input().split())
ans = 0
while True:
    if n > k:
        i = n // k + 1
        n = abs(n - k*i)
        continue
    elif n == k:
        ans = 0
        break
    elif n < k:
        if abs(n - k) > n:
            ans = n
            break
        else:
            ans = k - n
            break

print(ans)

Measured memory_bytes: 38408
#include <bits/stdc++.h>
using namespace std;
void bbs(vector<int> &a,int n,int &e){
  
  int f=1;
  for(int i=0;f;i++){
    f=0;
    for(int j=n-1;j>=i+1;j--){
      if(a[j]<a[j-1]){
        swap(a[j],a[j-1]);
        e++;
        f=1;
      }
    }
  }
  return ;
}
int main(){
  int n;
  cin>>n;
  int f=0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  bbs(a,n,f);
  for(int i=0;i<n;i++){
    if(i==n-1){
      cout<<a[i];
    }
    else{
      
    cout<<a[i]<<" ";
    }
  }
  cout<<endl;
  cout<<f<<endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define MOD2 (lli) 998244353  
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int n,k;
string s;

void read(){
  cin >> n >> k;
  cin >> s;  
}

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

  read();

  int ii = 0, jj = 0;

  int ans = 0;
  while(ii < sz(s)){
    if(s[ii] == 'L'){
      jj = ii;
      while(s[jj] == 'L'){
        jj++;
      } 
      ans += (jj - ii)-1;
      ii = jj-1;
    } else {
      jj = ii;
      while(s[jj] == 'R'){
        jj++;
      }
      ans += (jj - ii)-1;
      ii = jj-1;
    }
    ii++;
  }
  // cout << ans << endl;

  cout << min(n-1, ans+(2*k)) << endl;

  return 0;
}

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

int main(void)
{
	string s;

	getline(cin, s);
	stringstream ss(s);
	string a;

	string o = "";
	while(ss >> a)
		o += toupper(a[0]);

	cout << o << endl;

	return 0;
}

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

string str_number(int num,int digit){
	ostringstream ostr;
	ostr << setfill('0') << setw(digit) << num;
	return ostr.str();
}

int min_number(string str){
	sort(str.begin(),str.end());
	return stoi(str);
}

int max_number(string str){
	sort(str.begin(),str.end());
	return stoi(string(str.rbegin(),str.rend()));
}

int main(){
	int a,l;
	while(cin >> a >> l,l){
		vector<int> records;
		while(find(records.begin(),records.end(),a) == records.end()){
			records.emplace_back(a);
			a = max_number(str_number(a,l)) - min_number(str_number(a,l));
		}
		auto it = find(records.begin(),records.end(),a);
		cout << distance(records.begin(),it) << " " << a << " " << distance(it,records.end()) << endl;
	}
	return 0;
}

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

int main()
{
  int a,b;

  cin>>a>>b;

 
  if (a<b){
    cout << "a < b" << endl;
  } else if(a>b) {
    cout << "a > b" << endl;
  } else {
    cout << "a == b" << endl;
  }
  
  return 0;
}

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

int main()
{
    int n,k,i,s=0;

    cin>>n>>k;

    int a[n+5];

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

    for(i=0;i<k;i++){
        s=s+a[i];
    }
    cout<<s<<endl;

    return 0;
}



Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import math

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

if N == 1 :
  print ("Hello World")
else :
  A = int(input())
  B = int(input())
  print (A+B)

Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
vector<ll> A;
ll N, K;

bool isOK(ll x) {
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum += ceil((long double)A[i] / x - 1);
  }
  if (K >= sum)
    return true;
  else
    return false;
}

ll binary_search() {
  ll left = 0;
  ll right = 1e9 + 1;
  while (right - left > 1) {
    ll mid = left + (right - left) / 2;
    if (isOK(mid))
      right = mid;
    else
      left = mid;
  }
  return right;
}

int main() {
  cin >> N >> K;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = binary_search();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4784
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const long long INF = 1LL << 60;
ll MOD = 1e9+7;

int main() {

    long double A,B; cin>>A>>B;
    cout<<(ll)(A*B+0.001)<<endl;

}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1e9+7)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n){
        cin >> p[i];
    }

    int ans = 0;
    for (int i = 1; i < n-1; i++)
    {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])) ans++;
    }
    pr(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	int k, ans;
	cin >> k;
	if(k%2 == 0) ans = (k/2)*(k/2);
	else ans = (k/2)*(k/2+1);
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
n = gets(chomp:true).to_i
array = []

n.times do
  order, value, value2 = gets.split.map(&:to_i)
  case order
  when 0
    value == 0 ? array.unshift(value2) : array << value2
  when 1
    puts array[value]
  when 2
    value == 0 ? array.shift : array.pop
  end
end


Measured memory_bytes: 11516
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner input = new Scanner(System.in);
		int size = input.nextInt();
		int[] arr = new int[size];
		
		for(int i = 0; i < size; i++) {
			arr[i] = input.nextInt();
		}
		
		System.out.println(total(arr));
		input.close();
	}
	public static boolean prime(int x) {
		for(int i = 2; i <= (int) Math.sqrt(x); ++i) {
            if(x % i == 0) {
                return false;
            }
        }
		return true;
	}
	
	public static int total(int[] arr) {
		int total = 0;
		for(int i = 0; i < arr.length; i++) {
			if(prime(arr[i])) {
				total++;
			}
		}
		return total;
	}
	
}


Measured memory_bytes: 42012
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    vector<vector<int>> adj(n);
    for(auto &i:h){
        cin >> i;
    }
    while(m--){
        int u,v;
        cin >> u >> v;
        u--;v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int count=0;
    for(int i=0;i<n;i++){
        bool flag=1;
        for(auto v:adj[i]){
            //cout<<v<<endl;
            if(h[i]<=h[v]){
                flag=0;
                break;
            }
        }
        count+=(flag?1:0);
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 8688
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
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()
    s = list(input())
    ans = 0
    for i in range(1000):
        k = str(i)
        while len(k) < 3:
            k = "0"+k
        l = 0
        for j in range(n):
            if k[l] == s[j]:
                l += 1
                if l == 3:
                    ans += 1
                    break
    print(ans)
    return

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


Measured memory_bytes: 41968
package main
import (
	"sort"
	"fmt"
	"strings"
)

func main(){
	var s string
	fmt.Scan(&s)
	split := strings.Split(s, "")
	sort.Strings(split)
	if "abc" == strings.Join(split, ""){
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)


func solve(X int64) (i int64) {
	var n int64 = 100
	for {
		if (n >= X) {
			return i
		}
		n = int64(float64(n) * 1.01)
		i++
	}
}

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func nextInt() int {
    sc.Scan()
    hoge := sc.Text()
    i, e := strconv.Atoi(hoge)
    if e != nil {
        panic(e)
    }
    return i
}

func nextInt64() int64 {
    sc.Scan()
    hoge := sc.Text()
    i, e := strconv.ParseInt(hoge, 10, 64)
    if e != nil {
        panic(e)
    }
    return i
}



func main() {
	sc.Split(bufio.ScanWords)
	X := nextInt64()
	// A, B := nextInt(), nextInt()
	fmt.Print(solve(X))

}

Measured memory_bytes: 1760
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

class SCC:
    def __init__(self, n):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.graph_rev = [[] for _ in range(n)]
        self.already = [False]*n
    
    def add_edge(self, fr, to):
        if fr == to:
            return
        self.graph[fr].append(to)
        self.graph_rev[to].append(fr)
    
    def dfs(self, node, graph):
        self.already[node] = True
        for n in graph[node]:
            if self.already[n]:
                continue
            self.dfs(n, graph)
        self.order.append(node)
    
    def first_dfs(self):
        self.already = [False]*self.n
        self.order = []
        for i in range(self.n):
            if self.already[i] == False:
                self.dfs(i, self.graph)
    
    def second_dfs(self):
        self.already = [False]*self.n
        self.ans = []
        for n in reversed(self.order):
            if self.already[n]:
                continue
            self.already[n] = True
            self.order = []
            self.dfs(n, self.graph_rev)
            self.order.reverse()
            self.ans.append(self.order)

    def scc(self):
        self.first_dfs()
        self.second_dfs()
        return self.ans


def main():
    n, m = map(int, input().split())
    scc = SCC(n)

    for i in range(m):
        a, b = map(int, input().split())
        scc.add_edge(a, b)
    
    scc_list = scc.scc()

    print(len(scc_list))
    for s in scc_list:
        print(len(s), end=" ")
        print(*s)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 267384
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }

int main() {

	double res = 0;
	long N; cin >> N;

	double a[1000]; for (int i = 0; i < N; i++) cin >> a[i];

	for (int i = 0; i < N; i++) res += (1 / a[i]);

	res = 1 / res;

	cout << setprecision(20) << res << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;

	




int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

ll x,y;
cin>>x>>y;
if(x>y && (x-y)%2==0)
	cout<<(x+y)/2<<"\n";
if(y>=x && (y-x)%2==0)
	cout<<(y+x)/2<<"\n";

if(abs(x-y)%2!=0)
	cout<<"IMPOSSIBLE"<<"\n";


}		





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

using namespace std;

using ll = long long;

int main() {
    int n;
    int x, a;
    cin >> n >> x;
    vector<int> input;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        input.push_back(a);
    }
    ll count = 0;
    for (int i=0; i<input.size()-1; ++i) {
        ll tempSum = input[i]+input[i+1];
        if (tempSum > x) {
            ll eat = tempSum-x;
            if (eat > input[i+1]) {
                input[i] -= eat-input[i+1];
                input[i+1] = 0;
            } else {
                input[i+1] -= eat;
            }
            count += eat;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 892
"""
i番目のゲートは LiからRiまでのIDカードのうちどれか1枚を持っていれば通過できます
"""

N, M = map(int, input().split())
left = 0
right =float("inf")

for i in range(M):
    L, R = map(int, input().split())
    if left<L:
        left = L
    if right > R:
        right = R

print(max(right-left+1,0))

Measured memory_bytes: 43480
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int room[][][] = new int[4][3][10];
		int b, f, r, v = 0;
		for (int i = 0; i < n; i++) {
			b = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			v = sc.nextInt();

			room[b - 1][f - 1][r - 1] +=v;
		}

		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 10; k++) {
					System.out.print(" " + room[i][j][k]);
				}
				System.out.println();
			}
			if (!(i == 3))
				System.out.println("####################");

		}

	}
}

Measured memory_bytes: 30028
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

signed main() {
    char a, b;
    cin >> a >> b;
    if(a=='H') {
        if(b=='H') {
            cout << 'H' << endl;
        } else {
            cout << 'D' << endl;
        }
    } else {
        if(b=='H') {
            cout << 'D' << endl;
        } else {
            cout << 'H' << endl;
        }
    }    
    return 0;
}

Measured memory_bytes: 256
from heapq import *
from collections import defaultdict
INF = float('inf')
class Prim:

    def __init__(self,N):#Nはグラフのノード数
        self.N = N
        self.cost = defaultdict(list)
        self.used = [False for _ in range(N)]
    
    def setcost(self,u,v,w):
        self.cost[u].append((v,w))
        self.cost[v].append((u,w))
    
    def prim(self):
        que = []
        heapify(que)
        used = self.used
        for e in self.cost[0]:
            heappush(que,[e[1],e[0]])
        used[0] = True
        res = 0
        while que:
            p = heappop(que)
            cos,v = p
            if used[v]:continue
            self.used[v] = True
            for e in self.cost[v]:
                if not used[e[0]]:
                    heappush(que,[e[1],e[0]])      
            res += cos
        return res

def main():
    N = int(input())
    cost = []
    for i in range(N):
        x,y = map(int,input().split())
        cost.append((x,y,i))
    prim = Prim(N)
    x = tuple(sorted(cost,key=lambda x: x[0]))
    y = tuple(sorted(cost,key=lambda x: x[1]))
    for i in range(N-1):
        a,b,u = x[i]
        c,d,v = x[i+1]
        w = min(abs(a-c),abs(b-d))
        prim.setcost(u,v,w)
        e,f,s = y[i]
        g,h,t = y[i+1]
        u = min(abs(e-g),abs(f-h))
        prim.setcost(s,t,u)
    ans = prim.prim()
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 82428
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    f = 0
    cnt = 0
    for i in range(n):
        if i != 0:
            if f == 0:
                if a[i] > a[i-1]:
                    f = 1
                elif a[i] < a[i-1]:
                    f = -1
                else:
                    f = 0
            else:
                if f == 1 and a[i] >= a[i-1]:
                    continue
                elif f == -1 and a[i] <= a[i-1]:
                    continue
                else:
                    cnt += 1
                    f = 0
    print(cnt + 1)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 62704
N = int(input())
nums = list(map(int, input().split(' ')))
flag = False
for i in range(N):
  if nums[i]%2 == 0 :
    
    if (nums[i]%3 != 0) & (nums[i]%5 != 0):
      flag = True
      print('DENIED')
      break
    else:
      continue
  else:
    continue
if flag == False:
  print('APPROVED')

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

int main(void)
{
    int n;
    vector<tuple<string, int, int>> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string tmps;
        int tmpp;
        cin >> tmps >> tmpp;
        s.push_back(make_tuple(tmps, 100 - tmpp, i));
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n; i++) {
        cout << get<2>(s[i]) + 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 5e5 + 5;

ll fact[maxn];

ll C(ll n, ll k) {
    return mul(fact[n], inv(mul(fact[n - k], fact[k])));
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("output.txt", "w", stdout);
    ll n, m, k; cin >> n >> m >> k;
    vector<ll>a(n), b(m);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (ll i = 0; i < m; i++) {
        cin >> b[i];
    }
    ll ans = 0;

    vector<ll>prefa(n), prefb(m);
    for (ll i = 0; i < n; i++) {
        prefa[i] = (i ? prefa[i - 1] : 0) + a[i];
    }
    for (ll i = 0; i < m; i++) {
        prefb[i] = (i ? prefb[i - 1] : 0) + b[i];
    }

    for (ll i = 0; i <= n; i++) {
        ll x = (i ? prefa[i - 1] : 0);
        if (x <= k) {
            ll kk = k - x;
            ll id = upper_bound(all(prefb), kk) - begin(prefb);
            ans = max(ans, id + i);
        }
    }


    cout << ans << endl;

    return 0;
}

/*

*/

Measured memory_bytes: 9520
N,x = map(int,input().split())
a = list(map(int,input().split()))
res = 10**18
d = [[0]*N for _ in range(N)]
for i in range(N):
    d[i][0] = a[i]
    for k in range(1,N):
        d[i][k] = min(d[i][k-1], a[i-k])

for k in range(N-1,-1,-1):
    tmp = k*x
    tmp += sum([d[i][k] for i in range(N)])
    res = min(res,tmp)
print(res)

Measured memory_bytes: 75228
h = {}
MOD = 10**9 + 7
INF = 10**18+1
ans = 0
def modPow(a, n)
  r = 1
  while n > 0
    r = r * a % MOD if n&1>0
    n >>= 1
    a = a * a % MOD
  end
  r
end
gets.to_i.times do |i|
  a, b = gets.split.map &:to_r
  if a==0 && b== 0
    ans += 1
    next
  end
  c, d = if a==0
    [INF, 0]
  elsif b==0
    [0, INF]
  else
    [b/a, -a/b]
  end
  if c < d
    h[c] ||= [0, 0]
    h[c][0] += 1
  else
    h[d] ||= [0, 0]
    h[d][1] += 1
  end
end
k = 1
h.each do |_, v|
  s = modPow(2, v[0]) + modPow(2, v[1]) - 1
  ans += k * (s-1) % MOD
  k = k * s % MOD
end
p ans % MOD

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

int main() {
	std::string o, e;
	std::cin >> o >> e;

	for (int i = 0; i < e.size(); ++i)
		std::cout << o[i] << e[i];

	if (o.size() > e.size())
		std::cout << o.back();

	std::cout << std::endl;
}

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

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

using ll = long long;
using P = pair<int,int>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main(){
    int N;
    cin>>N;
    vector<vector<ll>> g(N,vector<ll>(N));
    rep(i,N){
        rep(j,N) cin>>g[i][j];
    }
    bool can = true;
    rep(k,N){
        rep(i,N){
            rep(j,N){
                if(chmin(g[i][j],g[i][k]+g[k][j])) can = false;
            }
        }
    }
    if(!can) cout<<-1<<endl;
    else{
        ll mi = 0;
        rep(i,N){
            rep(j,N){
                bool nes = true;
                rep(k,N){
                    if(k==i||k==j) continue;
                    if(g[i][j]==g[i][k]+g[k][j]){
                        nes = false;
                        break;
                    }
                }
                if(!nes) mi+=g[i][j];
            }
        }
        ll ans = 0;
        rep(i,N){
            rep(j,N) ans+=g[i][j];
        }
        ans-=mi;
        cout<<ans/2<<endl;
    }
}

Measured memory_bytes: 4336
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {

	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			int n = (int) sc.scanLong();
			int minus = 0;
			int min = Integer.MAX_VALUE;
			long sum = 0;
			for (int i = 0; i < n; ++i) {
				int val = (int) sc.scanLong();
				if (val < 0)
					++minus;
				sum += Math.abs(val);
				min = Math.min(min, Math.abs(val));
			}
			if (minus % 2 == 0)
				System.out.println(sum);
			else
				System.out.println(sum - (min<<1));
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


Measured memory_bytes: 33448
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll N;
//区間ごとにanが何回採用されるかを求めると良い
int main(){

    ll N;
    cin >> N;

    //vector<ll > A(N, 0);
    vector<ll > idx(N+2, 0);

    for(ll i = 1; i <= N; i++){
        ll t; cin >> t;
        //各要素の位置を記録
        idx[t] = i;
    }

    ll ans = 0;

    //番兵を挿れておく
    set<ll > usedIdx = {0, N+1};
    //小さい値からその左右に自分より小さい要素がどの位置にあるかを調べる
    //つまり，自分より小さい要素があるところまでの区間では自分が採用される
    //逐次，setに自分の位置を追加しながら調べていく
    
    for(ll i = 1; i <= N; i++){
        //右側で自分より小さい要素の位置(自分以上の最小)
        auto right_idx = usedIdx.lower_bound(idx[i]);
        //左側で自分より小さい要素の位置(自分以下の最大)
        auto left_idx = usedIdx.lower_bound(idx[i]);
        if(*left_idx > idx[i]) left_idx--;
        //追加
        usedIdx.insert(idx[i]);
        //答え更新
        ans += ((idx[i] - *left_idx) * (*right_idx - idx[i])) * i;
        //cout << ((idx[i] - *left_idx) * (*right_idx - idx[i])) << endl;
        //cout << "left:" << *left_idx << "right:" <<*right_idx << endl;

    }

    cout << ans << endl;


} 

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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

  ll min,max;
  if(a%x==0){
    min=a/x;
  }else{
    min=a/x+1;
  }
  max=b/x;
  cout << max-min+1 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;


int main(){

   char buf[1010];
   fgets(buf,1010,stdin);

   for(int i=0;buf[i] != '\0';i++){
	 if(i >= 4 && buf[i] == 'e' && buf[i-1] == 'l' && buf[i-2] == 'p' &&
			   buf[i-3] == 'p' && buf[i-4] == 'a'){
		   buf[i-4] = 'p';
		   buf[i-3] = 'e';
		   buf[i-2] = 'a';
		   buf[i-1] = 'c';
		   buf[i] = 'h';
	   }else if(i >= 4  && buf[i] == 'h' && buf[i-1] == 'c' && buf[i-2] == 'a' &&
			   buf[i-3] == 'e' && buf[i-4] == 'p'){
		   buf[i-4] = 'a';
		   buf[i-3] = 'p';
		   buf[i-2] = 'p';
		   buf[i-1] = 'l';
		   buf[i] = 'e';
	   }
   }

   printf("%s",buf);

    return 0;
}


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

int main()
{
	ll n,a,b;
	cin >> n >> a >> b;
	if(abs(a - b) % 2 == 0){
		printf("%lld\n",abs(a - b) / 2);
	}
	else{
		ll sum = 0;
		if(n - b < a - 1){
			sum = n - b + 1;
			sum += (b - a)/2;
		}
		else{
			sum = a;
			sum += (b - a - 1)/2;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveD();
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		Set<Edge> edgeSet = new HashSet<Edge>();
		for (int i = 0; i < M; i++) {
			Edge e = new Edge();
			e.src = sc.nextInt();
			e.dest = sc.nextInt();
			e.cost = sc.nextLong();
			edgeSet.add(e);
		}

		Map<Integer, Long> pointMap = new HashMap<>();
		pointMap.put(1, 0L);
		Long ans = null;
		for (int calcNum = 1; calcNum < 2 * N; calcNum++) {
			for (Edge e : edgeSet) {
				if (pointMap.containsKey(e.src)) {
					long destValue = Long.MIN_VALUE;
					if (pointMap.containsKey(e.dest)) {
						destValue = pointMap.get(e.dest);
					}
					long nextValue = pointMap.get(e.src) + e.cost;
					if (destValue < nextValue) {
						pointMap.put(e.dest, nextValue);
					}
				}
			}
			if (calcNum == N - 1) {
				ans = pointMap.get(N);
			}
		}
		if (ans.equals(pointMap.get(N))) {
			System.out.println(ans);
		} else {
			System.out.println("inf");
		}
	}

	class Edge {
		public int src;
		public int dest;
		public long cost;
	}
}

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

#include <vector>
#include <algorithm>
int main(){
  int n,k; cin >> n >> k;
  vector<int> p(n);
  for(int i=0; i<n; i++) cin >> p[i];
  sort(p.begin(),p.end());
  int ans = 0;
  for(int i=0; i<k; i++) ans += p[i];
  cout << ans << endl;
}

Measured memory_bytes: 3640