akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main() {
    int n;
    cin>>n;
    vll a(n);
    rep(i,n)cin>>a.at(i);
    vll ans(2001,0);
    
    
    for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<20> s(tmp);  // 最大20個なので20ビットのビット列として扱う
 
    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (s.test(i)) {
        sum += a.at(i);
      }
    }
    if (sum <= 2000) {
      ans.at(sum)=1;
    }
  }
  
    
    int m;
    cin>>m;
    rep(i,m){
        ll k;
        cin>>k;
        if(ans.at(k)==1)cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int a,b,c,d,i;//10 9 10 10
	cin>>a>>b>>c>>d;
	for(i=1;i<=100;i++)
		{
			if(i%2!=0)
			{
				c-=b;
					if(c<=0)
					break;
				
			}
			else
			{
				a-=d;
			if(a<=0)
			break;
			}
			
		
		}
//	cout<<a<<c;
	if(a<c)
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3528
inStr = input().split()
M = int(inStr[0])
D = int(inStr[1])

count = 0

for i in range(1, M+1):
  for j in range(1,D+1):
    q, mod = divmod(j, 10)
    if q >= 2 and mod >= 2:
      if i == q * mod:
        count += 1
print(count)

Measured memory_bytes: 3064
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<utility>
#include<stdio.h>
#include<vector>
#include<string>
#include<math.h>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#pragma warning(disable:4244)
#define PI 3.1415926536
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll ll_inf = 9223372036854775807;
const int int_inf = 2147483647;
const short short_inf = 32767;
const char char_inf = 127;
inline ll read() {
	ll c = getchar(), Nig = 1, x = 0;
	while (!isdigit(c) && c != '-')c = getchar();
	if (c == '-')Nig = -1, c = getchar();
	while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
	return Nig * x;
}
inline void out(ll a)
{
	if (a < 0)putchar('-'), a = -a;
	if (a >= 10)out(a / 10);
	putchar(a % 10 + '0');
}
ll qpow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1)res = (res * x) % mod;
		x = (x * x) % mod; n >>= 1;
	}
	return res;
}
#define read read()
int save[200][200];
int main()
{
	int n = read;
	for (int i = 1; i <= n; i++)
	{
		int temp = i;
		int len = log10(i);
		int N = pow(10, len);
		int num = temp / N;
		save[num][i % 10]++;
	}
	int ans = 0;
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
			ans += save[i][j] * save[j][i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll l, r, a;
  in2(l, r);
  if(r - l > 2019){
    out(0);
    memi;
    return 0;
  }
  a = 2019;
  rep2(i, l, r){
    rep2(j, i + 1, r + 1){
      a = min(a, i * j % 2019);
    }
  }
  out(a);
  memi;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    llong inner_right = tx-sx;
    llong inner_up  = ty-sy;
    llong outer_right = inner_right+1;
    llong outer_up  = inner_up+1;

    for(int i=0; i<inner_right; i++){
        cout << "R";
    }
    for(int i=0; i<inner_up; i++){
        cout << "U";
    }
    for(int i=0; i<inner_right; i++){
        cout << "L";
    }
    for(int i=0; i<inner_up; i++){
        cout << "D";
    }
    cout << "L";
    for(int i=0; i<outer_up; i++){
        cout << "U";
    }
    for(int i=0; i<outer_right; i++){
        cout << "R";
    }
    cout << "D";
    cout << "R";
    for(int i=0; i<outer_up; i++){
        cout << "D";
    }
    for(int i=0; i<outer_right; i++){
        cout << "L";
    }
    cout << "U" << endl;
    return 0;
}

//UURDDLLUUURRDRDDDLLU
//RUULDDLUUURRDRDDDLLU


Measured memory_bytes: 3156
import Text.Printf
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
main=putStr.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:a:b:vs)=unlines[printf"%.6f"ra,show rc]where
  ws=(V.dropWhile=<<((>).(V.!(n-a)))).V.fromList.sort$vs
  k=V.length ws
  m=if k==a then 0 else V.length$(V.takeWhile=<<((==).V.head))ws
  c=V.generate(m+1)$ \i->if i==0 then 1 else c V.!(i-1)*(m-i+1)`div`i
  ra=x/y::Double where[x,y]=map fromIntegral[V.sum$V.slice(k-a)a ws,a]
  rc=sum$map(c V.!)$if k/=m then[a+m-k]else[a..min b m]

Measured memory_bytes: 4328
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        System.out.println(n + (n * n) + (n * n * n));
    }
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int n; cin >> n;
    vector<vector<pair<int, int>>> st(n);

    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        st[i].resize(a);
        for (int j = 0; j < a; j++) {
            int x, y; cin >> x >> y; x--;
            st[i][j] = make_pair(x, y);
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
        bool flag = true;
        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) {
                for (auto &p: st[i]) {
                    if (((bit >> p.first) & 1) != p.second) flag = false;
                }
            }
        }
        if (flag) ans = max(ans, __builtin_popcount(bit));
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main(){
    int N; cin >> N;
    vector<int> A(N), pos(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        pos[A[i] - 1] = i;
    }
    set<int> st;
    st.insert(-1);
    st.insert(N);

    long long ans = 0ll;
    for(int i=0;i<N;i++){
        auto itr = st.lower_bound(pos[i]);
        long long right = (*itr) - pos[i];
        --itr;
        long long left = pos[i] - (*itr);
        long long tmp = A[pos[i]] * left * right;
        ans += tmp;
        st.insert(pos[i]);
    }
    cout << ans << endl;

}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code
int main(int argc, char const* argv[])
{
	int n;
	string s;
	cin >> n >> s;
	VL rui_b(n+1,0);
	VL rui_w(n+1,0);
	for (int i = 0; i < n; i++) {
		rui_b[i+1] = rui_b[i];
		rui_w[i+1] = rui_w[i];
		if (s[i] == '#') {
			rui_b[i+1]++;
		}
		if (s[i] == '.') {
			rui_w[i+1]++;
		}
	}
	LL ans = INT32_MAX;
	for (int i = 0; i < n; i++) {
		if (s[i] == '#') {
			ans = min(ans, rui_b[i] + rui_w[n] - rui_w[i]);
		}
	}
	ans = min(ans, rui_b[n]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3716
//
// Created by tattsun on 2017/02/14.
//

#include <iostream>
#include <vector>

#define VERTEX_NUM_MAX 101

using namespace std;
typedef vector<int> Vertex;

int n;
Vertex vs[VERTEX_NUM_MAX];
int ds[VERTEX_NUM_MAX];

void _bfs(vector<int>& targets, int distance) {
    vector<int> next_targets;

    for(auto it = targets.begin(); it != targets.end(); it++) {
        if(ds[*it] == -1) {
            ds[*it] = distance;

            auto& t = vs[*it];
            for(auto itt = t.begin(); itt != t.end(); itt++)
                next_targets.push_back(*itt);
        }
    }

    if(next_targets.empty())
        return;

    _bfs(next_targets, distance+1);
}

void bfs() {
    vector<int> targets;
    targets.push_back(1);

    _bfs(targets, 0);
}

int main() {
    for(int i=0; i<VERTEX_NUM_MAX; i++) {
        ds[i] = -1;
    }

    cin >> n;

    int u, k, p;
    for(int i=1; i<=n; i++) {
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            cin >> p;
            vs[i].push_back(p);
        }
    }

    bfs();

    for(int i=1; i<=n; i++) {
        cout << i << " " << ds[i] << endl;
    }
}

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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

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...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

/*int ter_search(int l,int r)
{
    while((r-l)>0)
    {
        int m1=l+(r-l)/3;
        int m2=r-(r-l)/3;
        int f1=f(m1);
        int f2=f(m2);
        if(f1>f2)
         l=m1+1;
         else
          r=m2-1;
    }
    return f(l);
}*/

int fact[500005];

int choose(int n,int r)
{
   int a=fact[n];
   int b=(fact[r]%md*fact[n-r]%md)%md;
   a=(a%md*power_md(b,md-2)%md)%md;
   return a; 
}

int32_t main()
{
    fast;
    fact[0]=fact[1]=1;
    for(int i=2;i<500005;i++)
     fact[i]=(fact[i-1]%md*i%md)%md;
     int n,m;
     cin>>n>>m;
     if(m<n)
     {
         cout<<0<<"\n";
         return 0;
     }
    int a=choose(m,n);
    a=(a%md*fact[n]%md)%md;
    int s=1;
    int res=0;
    for(int j=0;j<=n;j++)
    {
        int b=choose(n,j)%md;
        b=(b%md*choose(m-j,n-j)%md)%md;
        b=(b%md*fact[n-j]%md)%md;
        b*=s;
        res=(res+b%md+md)%md;
        s=-s;
    }
    cout<<(a%md*res%md)%md<<"\n";
    return 0;
}

Measured memory_bytes: 7548
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)





#define MAX_V 1000

struct edge{int to,cost;};
vector<edge> G[MAX_V];

int shortest_path(int s,vector<int> &d){
	int v = d.size();
	rep(i,d.size())d[i]=INF;
	d[s]=0;
	rep(loop,v){
		bool update = false;
		rep(i,MAX_V){
			for(auto e:G[i]){
				if(d[i]!=INF && d[e.to] > d[i]+e.cost){
					d[e.to] = d[i]+e.cost;
					update = true;
				}
			}
		}
		if(!update)break;
		if(loop==v-1)return true;	//negative_cycle
	}
	return false;
}


int main(){
	int v,e,r;
	cin>>v>>e>>r;
	
	rep(i,e){
		int u,v,d;
		cin>>u>>v>>d;
		G[u].pb({v,d});
	}
	
	vector<int> d(v);
	bool res = shortest_path(r,d);
	if(res==true)cout<<"NEGATIVE CYCLE"<<endl;
	else{
		rep(i,v){
			if(d[i]==INF)cout<<"INF"<<endl;
			else cout<<d[i]<<endl;
		}
	}
}

Measured memory_bytes: 3160
import Control.Applicative
import Control.Monad
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = do
  q <- readLn
  solve <$> replicateM q f >>= mapM_ print
  where
    f = readil B.readInt <$> B.getLine

solve :: [[Int]] -> [Int]
solve = toListZ . foldl' f emptyZ
  where
    f z [0, x] = insertZ z x
    f z [1, d] = moveZ z d
    f z [2] = eraseZ z

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')

type Zipper a = ([a], [a])

emptyZ :: Zipper Int
emptyZ = ([], [])

insertZ :: Zipper Int -> Int -> Zipper Int
insertZ (as, bs) x = (as, x:bs)

moveZ :: Zipper Int -> Int -> Zipper Int
moveZ z d = f z d
  where
    f (as, bs) d
      | d == 0 = (as, bs)
      | d > 0 = case bs of
                 (b:bs) -> f (b:as, bs) (d - 1)
                 [] -> (as, [])
      | otherwise = case as of
                     (a:as) -> f (as, a:bs) (d + 1)
                     [] -> ([], bs)

eraseZ :: Zipper Int -> Zipper Int
eraseZ (as, bs) = case bs of
                   [] -> (as, [])
                   (b:bs) -> (as, bs)

toListZ :: Zipper Int -> [Int]
toListZ (as, bs) = reverse as ++ bs



Measured memory_bytes: 159796
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n, k, c;
    cin >> n >> k >> c;
    vi v;
    rep(i, n)
    {
        char tmp;
        cin >> tmp;
        if (tmp == 'o')
            v.emplace_back(i);
    }

    if (c == 0 && v.size() > k)
        return 0;

    vi ans;
    map<int, int> mp;
    int bef = -INF;
    int cnt = 0;
    rep(i, v.size())
    {
        int tmp = v[i];
        if (tmp - bef > c)
        {
            mp[tmp] = 0;
            bef = tmp;
            cnt++;
        }
        if (cnt == k)
            break;
    }

    bef = INF;
    cnt = 0;
    rep(i, v.size())
    {
        int tmp = v[v.size() - 1 - i];
        if (bef - tmp > c)
        {
            if (mp.count(tmp))
                ans.emplace_back(tmp);
            bef = tmp;
            cnt++;
        }
        if (cnt == k)
            break;
    }

    sort(all(ans));
    rep(i, ans.size())
    {
        cout << ans[i] + 1 << endl;
    }

    return 0;
}

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

using namespace std;
typedef pair<int, int> P;
const int MAXH = 301;
const int MAXW = 301;
const int MAXQ = 1e5 + 10;

int a[MAXH][MAXW];
P field[MAXH*MAXW];
bool visited[MAXH*MAXW];
vector<int> cost[MAXH*MAXW];
int l[MAXQ], r[MAXQ];

int h, w, d, q;
void solve() {
  for (int y=0;y<h;y++) {
    for (int x=0;x<w;x++) {
      field[a[y][x] - 1] = P(x, y);
    }
  }

  for (int i=0;i<=w*h;i++) {
    if (!visited[i]) {
      cost[i].push_back(0);
      for (int j=1;i + j * d<=w*h;j++) {
        visited[i + j * d] = true;
        P& p1 = field[i + (j-1) * d];
        P& p2 = field[i + j * d];
        cost[i].push_back(cost[i][j-1] + abs(p1.first - p2.first) + abs(p1.second - p2.second));
      }
    }
  }


  for (int i=0;i<q;i++) {
    l[i]--;r[i]--;
    int start = l[i] % d;
    cout << (cost[start][(r[i] - start) / d] - cost[start][(l[i] - start) / d]) << endl;
  }
}

int main() {
  cin >> h >> w >> d;
  for (int y=0;y<h;y++) {
    for (int x=0;x<w;x++) {
      cin >> a[y][x];
    }
  }
  cin >> q;
  for (int i=0;i<q;i++) {
    cin >> l[i] >> r[i];
  }
  solve();
}


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

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

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());
    ll ans = A[0];
    rep(i, N - 2) ans += A[i / 2 + 1];
    cout << ans << endl;
}

Measured memory_bytes: 4792
n=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(2,n):
  if (abs(h[i]-h[i-2])+dp[i-2])<=(abs(h[i]-h[i-1])+dp[i-1]):
    dp.append(dp[i-2]+abs(h[i]-h[i-2]))
  else:
    dp.append(dp[i-1]+abs(h[i]-h[i-1]))
print(dp[-1])

Measured memory_bytes: 13928
#include <stdio.h>
#include <math.h>

int main()
{
    long long int ans,sum,i;
    scanf("%lld",&ans);
    for( i=1;;i++)
    {
        if((1+i)*i/2>=ans)
        {
            sum=(i+1)*i/2;
            break;
        }
    }

    printf("%lld",i);

}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int dp[110][4][4][4];
int main() {
    int N;
    cin >> N;
    long long MOD = pow(10, 9) + 7;
    
    dp[0][3][3][3] = 1;
    for (int i = 0; i < N; i++) {
        for (int a1 = 0; a1 < 4; a1++) {
            for (int a2 = 0; a2 < 4; a2++) {
                for (int a3 = 0; a3 < 4; a3++) {
                    for (int a4 = 0; a4 < 4; a4++) {
                        if (a2 == 0 && a3 == 1 && a4 == 2) continue;
                        if (a2 == 0 && a3 == 2 && a4 == 1) continue;
                        if (a2 == 2 && a3 == 0 && a4 == 1) continue;
                        if (a1 == 0 && a2 == 2 && a4 == 1) continue;
                        if (a1 == 0 && a3 == 2 && a4 == 1) continue;

                        dp[i + 1][a2][a3][a4] += dp[i][a1][a2][a3];
                        dp[i + 1][a2][a3][a4] %= MOD;
                    }
                }
            }
        }
    }

    long long ans = 0;
    for (int a1 = 0; a1 < 4; a1++) {
        for (int a2 = 0; a2 < 4; a2++) {
            for (int a3 = 0; a3 < 4; a3++) {
                ans += dp[N][a1][a2][a3];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> request(m);
    for(int i = 0; i < m; i++)
    {
        cin >> request[i].second >> request[i].first;
    }
    sort(request.begin(), request.end());
    vector<int> ans;
    ans.push_back(request[0].first-1);
    for(int i = 1; i < m; i++)
    {
        bool flag = false;
        for(int j = 0; j < ans.size(); j++)
        {
            if (ans[j] >= request[i].second && ans[j] < request[i].first) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            ans.push_back(request[i].first-1);
        }
    }
    cout << ans.size() << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int x=s.length();
	int y=t.length();
	s=" "+s;
	t=" "+t;
	int dp[x+1][y+1];
    int pp[x+1][y+1];
    for (int i=0; i<=x; i++)
        dp[i][0]=0;
    for (int i=1; i<=y; i++)
        dp[0][i]=0;
	for (int i=1; i<=x; i++)
	{
		for (int j=1; j<=y; j++)
		{
			if(s[i]==t[j])
			{
				dp[i][j]=dp[i-1][j-1]+1;
				pp[i][j]=0;
			}
			else
			{
				if(dp[i-1][j]>=dp[i][j-1])
				{
					dp[i][j]=dp[i-1][j];
					pp[i][j]=-1;
				}
				else
				{
					dp[i][j]=dp[i][j-1];
					pp[i][j]=1;
				}
			}	
		}
	}
	string ans="";
	int i=x, j=y;
	while (i!=0 && j!=0)
	{
	    if(pp[i][j]==0)
	    {
	        ans=s[i]+ans;
	        i--;
	        j--;
	    }
	    else if(pp[i][j]==1)
	        j--;
	    else
	        i--;
	}
	//cout<<dp[x][y]<<endl;
	cout<<ans<<endl;
}

Measured memory_bytes: 70656
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		sc.close();
		long ans = K;
		for(int i = 1; i < N; i++) {
			ans *= (K - 1);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

    int N;
    cin >> N;
    vector<int> L(N);
    REP(i, N) cin >> L[i];
    sort(L.begin(), L.end());

    ull res = 0;

    REP(i, N) FOR(j, i+1, N) {
        int k = lower_bound(L.begin(), L.end(), L[i]+L[j]) - L.begin();

        res += max(k - (j+1), 0);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    vector<vector<int>> bingo(3, vector<int>(3));
    for (int i=0; i<3; i++)
        for (int j=0; j<3; j++)
            cin >> bingo[i][j];
    int n;
    cin >> n;
    vector<vector<bool>> check(3, vector<bool>(3, false));
    for (int i=0; i<n; i++) {
        int b;
        cin >> b;
        for (int j=0; j<3; j++)
            for (int k=0; k<3; k++)
                if (b == bingo[j][k])
                    check[j][k] = true;
    }

    bool ans = 0;
    for (int i=0; i<3; i++) {
        ans = ans || (check[i][0] && check[i][1] && check[i][2]);
        ans = ans || (check[0][i] && check[1][i] && check[2][i]);
    }
    ans = ans || (check[0][0] && check[1][1] && check[2][2]);
    ans = ans || (check[0][2] && check[1][1] && check[2][0]);

    cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 888
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3, x4, y3, y4;
    int dx = x2 - x1;
    int dy = y2 - y1;
    x3     = x2 - dy;
    y3     = y2 + dx;
    x4     = x1 - dy;
    y4     = y1 + dx;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[8]={ 1,0,-1,0,1,1,-1,-1 };
int dy[8]={ 0,1,0,-1,1,-1,1,-1 };

int N, M, R;
int r[8];
int cost[200][200];

signed main(){
	cin >> N >> M >> R;
	rep(i, R){
		cin >> r[i];
		r[i]--;
	}
	sort(r, r+R);
	rep(i, N){
		rep(j, N) cost[i][j] = 1e9;
		cost[i][i] = 0;
	}
	rep(i, M){
		int A, B, C;
		cin >> A >> B >> C;
		A--; B--;
		cost[A][B] = min(cost[A][B], C);
		cost[B][A] = min(cost[B][A], C);
	}

	rep(i, N){
		rep(j, N){
			rep(k, N){
				cost[j][k] = min(cost[j][k], cost[j][i]+cost[i][k]);
			}
		}
	}
	int ans = INT_MAX;
	do{
		int tmp = 0;
		rep(i, R-1){
			tmp += cost[r[i]][r[i+1]];
		}
		ans = min(ans, tmp);
	} while(next_permutation(r, r+R));
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
std::pair<long long, long long> a[200001];
bool comp(std::pair<long long, long long> X, std::pair<long long, long long> Y) {
    return X.first * X.first + X.second * X.second < Y.first * Y.first + Y.second * Y.second;
}
long long dist(std::pair<long long, long long> X) {
    return X.first * X.first + X.second * X.second;
}
int main () {
    long long n, d;
    std::cin >> n >> d;
    for (int i = 1; i <= n; i++) {
        std::cin>>a[i].first >> a[i].second;
    }
    std::sort(a+1, a+n+1, comp);
    int ans = 0;
    for (int i = 1; i <= n; i ++) {
        if (dist(a[i]) <= d * d) {
            ans++;
        }
        else{
            break;
        }
    }
    std::cout << ans << '\n';
}


Measured memory_bytes: 6724
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<ll,ll>> vii;
typedef vector<vii> vvii;
typedef pair<ll,ll> ii;
 
#define pb push_back
#define mp make_pair
#define sz(vs) (ll)(vs.size())
#define rep(i,a,b) for (ll i=a;i<b;i++)
#define iter(i,c) for (auto i:c)
#define ss second
#define ff first
#define D(x) cout << '>' << #x << ':' << x << endl;
#define D2(x,a) cout << '>' << #x << ':' << x << " >" << #a << ':' << a <<  endl;
#define D3(x,a,b) cout << '>' << #x << ':' << x << " >" << #a << ':' << a << " >" << #b << ':' << b << endl;
#define D4(x,a,b,c) cout << '>' << #x << ':' << x << " >" << #a << ':' << a << " >" << #b << ':' << b << " >" << #c << ':' << c << endl;
#define PS(a,st,e) if (1) {if (st<e) {cout<<a[st];rep(noname,st+1,e) cout<<""<<a[noname];}cout<<"\n";}
#define PA1(a,st,e) if (1) {if (st<e) {cout<<a[st];rep(noname,st+1,e) cout<<" "<<a[noname];}cout<<'\n';}
#define PA(a,st,e) if (1) {cout<<#a<<": [";if (st<e) {cout<<a[st];rep(noname,st+1,e) cout<<", "<<a[noname];}cout<<"]\n";}
#define PSET(c) if (1) {cout<<#c<<": {";for (auto noname:c) cout<<noname<<",";cout<<"}\n";}
#define PM(c) if (1) {cout<<#c<<": {";for (auto noname:c) cout<<noname.first<<":"<<noname.second<<", ";cout<<"}\n";}


#define MAXN 100005
#define mod 1000000007

ll n, x, a[MAXN];
string s;
char c;

void solve() {
	cin>>n;
	memset(a,0,sizeof(a));
	rep(i,0,n) {
		cin>>s;
		if (s.compare("AC")==0) a[0]++;
		if (s.compare("WA")==0) a[1]++;
		if (s.compare("TLE")==0) a[2]++;
		if (s.compare("RE")==0) a[3]++;
	}
	cout<<"AC x "<<a[0]<<endl;
	cout<<"WA x "<<a[1]<<endl;
	cout<<"TLE x "<<a[2]<<endl;
	cout<<"RE x "<<a[3]<<endl;
}
 
void aux() {
}
 
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	aux();
	ll _ = 1;
	// cin>>_;
	while(_--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 4436
// restoring trees. I need to solve the problem !

#include <bits/stdc++.h>
#define ll long long int 
using namespace std;


// Time complexity O(n)

int main() {

	ll n,m;
	cin>>n>>m;
	vector<int> cnt(n,0);
	int temp;
	for(int i = 0;i<2*m;i++){
		cin>>temp;
		cnt[temp-1]++;
	}

	int i;
	for(i = 0;i<n;i++){
		if(cnt[i]%2)
			break;
	}
	if(i==n)
		cout<<"YES";
	else
		cout<<"NO";

}

Measured memory_bytes: 640
import java.awt.Point;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			Stack<Point> table = new Stack<Point>();
			for (int i = 1; i <= n; i++) {
				int s = sc.nextInt();
				if (i % 2 == 0) {
					if (table.peek().x == s) {
						Point p = table.pop();
						p.y++;
						table.push(p);
					} else {
						Point p = table.pop();
						if (table.empty()) {
							p.x ^= 1;
							p.y++;
							table.push(p);
						} else {
							Point pp = table.pop();
							pp.y += p.y + 1;
							table.push(pp);
						}
					}
				} else {
					if (table.empty()) {
						table.push(new Point(s, 1));
					} else if (table.peek().x == s) {
						Point p = table.pop();
						p.y++;
						table.push(p);
					} else {
						table.push(new Point(s, 1));
					}
				}
				// System.out.println(i);
				// System.out.println(table);
			}
			int ans = 0;

			while (!table.empty()) {
				Point p = table.pop();
				if (p.x == 0) {
					ans += p.y;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
import Data.Ord
import Data.List

main = interact $ unlines . map (show . carden_lantern) . read' . lines
 where
  read' ("0":_) = []
  read' (n:m:xs) = (read n, map (parse . map read . splitOn ',') edge) : read' xs'
   where
    (edge,xs') = splitAt (read m) xs
    parse [a,b,d] = ((a,b), div d 100)

carden_lantern (n,edge) = count $ kruskal n $ sortBy (comparing snd) edge
 where count abd =  sum (map snd abd) - length abd

kruskal n edge = makepath (map return [0..n-1]) [] edge
 where
  makepath ts acc [] = acc
  makepath ts acc (((a,b),d):abd)
   | disjoint a b ts = makepath (link a b ts) ((((a,b),d)):acc) abd
   | otherwise = makepath ts acc abd
   where
    disjoint a b = not . any (\t -> elem a t && elem b t)
    link a b ts = let (ab,ts') = partition (\t -> elem a t || elem b t) ts in concat ab : ts'

splitOn c xs
 | null xs = []
 | head xs == c = splitOn c (tail xs)
 | otherwise = (takeWhile (/= c)) xs : splitOn c (dropWhile (/= c) xs)

Measured memory_bytes: 10300
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define dfor(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long

int main() {
	int t=1;
	cin>>t;
	cout<<t*t*t<<endl;
	
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 8
#define T 1
#define F -1

int B[N][N],row[N],col[N],dpos[2*N-1],dneg[2*N-1];

void printboard(){
    int i,j;
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(B[i][j]==T){
                if(row[i]!=j) return;
            }
       }
    }
    
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(row[i]==j) printf("Q");
            else          printf(".");
        }
        printf("\n");
    }
}

void backtrack(int i){
  int j;

  if(i==N){
    printboard();
    return;
  }

  for(j=0;j<N;j++){
    if(col[j]==T||dpos[i+j]==T||dneg[i-j+N-1]==T)    continue;
    row[i] =j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=T;
    backtrack(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=F;
  }
}

int main(void){
    int i,j,k,r,c;
    
    for(i=0;i<N;i++){
        row[i]=col[i]=F;
        for(j=0;j<N;j++) B[i][j]=F;
    }
    
    for(i=0;i<2*N-1;i++) dpos[i]=dneg[i]=F; 
    
    scanf("%d",&k);
    for(i=0;i<k;i++){
        scanf("%d %d",&r,&c);
        B[r][c]=T;
    }
    
    backtrack(0);    
    
    return 0;
}



Measured memory_bytes: 2148
N = int(input())
L = list(sorted(map(int, input().split())))
# N = 5
# L = sorted([100, 1, 2, 3, 14, 15, 58, 58, 58, 29])

x = 0
for i in range(0, 2 * N, 2):
    x += L[i]
print(x)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[1000000+5];
ll arr[1000000+5];
/*arr[0]=1;
dp[0]=1;*/
int main()
{
    /*ll n,x=1,i;
    cin>>n;
    ll mod=1000000007;
    ll dp[n+2]
    for(i=1;i<=n-1;i++)
    {
        x=x*2;
        x=x%mod;
    }
    x=x+n-1;
    x=x%mod;
    cout<<x;*/
    /*ll n;
    cin>>n;
    ll a[n],i;
    for(i=0;i<n;i++)
    {
        cin>>n;
    }*/
    ll n,i;
    cin>>n;
    ll mod=1000000007;
    ll dp[n+10];
    dp[0]=dp[1]=dp[2]=0;
    dp[3]=dp[4]=dp[5]=1;
    for(i=6;i<=n;i++)
    {
        dp[i]=(dp[i-1]+dp[i-3])%mod;
    }
    cout<<dp[n];
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    bool flg = false;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
        if(a[i] %2 == 1) flg = true;
    }
    if(flg) cout << "first" << endl;
    else cout << "second" << endl;
    return 0;
}


Measured memory_bytes: 640
'use strict';
const main = input => {
  const n = parseInt(input[0]);
  const p = input[1].split(' ').map(val => parseInt(val));
  const mins = [];
  mins[0] = p[0];
  let ans = 1;
  for(let i=1; i<n; i++) {
    mins[i] = mins[i-1]>p[i]?p[i]:mins[i-1];
    if (mins[i] == p[i]) ans++;
  }
  console.log(ans);
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  string n; cin >> n;
  cout << count(n.begin(), n.end(), '2') << endl;

  return 0;
}




Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n%M) * (f(n - 1) % M);
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll 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;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll A, B, N; cin >> A >> B >> N;
	
	ll x = min(B - 1, N);
	cout << (A * x / B) - A * (x / B) << endl;
}


Measured memory_bytes: 11024
import Data.Maybe
main :: IO()
main = do
  inputs <- getContents
  mapM_ (result.calc.readExpr) $ [line | line <-(lines inputs), length(line) > 0]

calc :: (Int, String, Int) -> Maybe Int
calc (a, op, b)
    | op == "+" = Just $ a + b
    | op == "-" = Just $ a - b
    | op == "*" = Just $ a * b
    | op == "/" = Just $ a `div` b
    | op == "?" = Nothing

readExpr :: String -> (Int, String, Int)
readExpr line = let [a, op, b] = words line
                in ((read a ::Int), op, (read b ::Int))

result :: Maybe Int -> IO()
result x | x == Nothing = return ()
         | otherwise = print $ fromJust x

Measured memory_bytes: 4104
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int fn(int i) {
	if (i % 2 == 0) return i / 2;
	else return 3 * i + 1;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//入力
	vector<int> a;
	int i = 0, j = 0,x; //内部で使用;
	int ans = 0; //出力

	cin >> x;
	a.push_back(x);
	i++;
	while(ans==0) {
		a.push_back(fn(a[i-1]));
		rep(j, i) {
			if (a[i] == a[j]) ans = i+1;
		}
		i++;
	}

	cout << ans << "\n";
}


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

int main() {
  int n;
  ll x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];

  ll ans = 0;
  if (a[0] > x) {
    ans += a[0] - x;
    a[0] = x;
  }
  rep(i, 0, n - 1) {
    if (a[i] + a[i + 1] <= x) continue;
    ans += a[i + 1] + a[i] - x;
    a[i + 1] -= a[i + 1] + a[i] - x;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

bool solve() {
  string in;
  getline(cin, in);
  if (in == "#") return false;
  string s;
  REP(i, SZ(in)) {
    if (in[i] != ' ') {
      s += in[i];
    }
  }
  s += ">>0";

  vll val = {-1};
  vll num = {0};

  REP(i, SZ(s)) {
    /*
    cout << i << endl;
    cout << val << endl;
    cout << num << endl;
    cout << endl;
     */
    if('0' <= s[i] && s[i] <= '9') {
      num.back() *= 10;
      num.back() += s[i] - '0';
    } else if(s[i] == 'S') {
      val.push_back(-1);
      num.push_back(0);
      i++;
    } else if(s[i] == '>' && i < SZ(s)-2 && s[i+1] == '>' && (('0' <= s[i+2] && s[i+2] <= '9') || s[i+2] == 'S')) {
      if(val.back() == -1) {
        val.back() = num.back();
        num.back() = 0;
      } else {
        while(val.back() > 0 && num.back() > 0) {
          val.back() /= 2;
          num.back()--;
        }
        num.back() = 0;
      }
      i++;
    } else if(s[i] == '>') {
      if(val.back() == -1) {
        val.back() = num.back();
        num.back() = 0;
      } else {
        while(val.back() > 0 && num.back() > 0) {
          val.back() /= 2;
          num.back()--;
        }
        num.back() = 0;
      }
      ll tmp = val.back();
      tmp *= tmp;
      tmp %= MOD;
      val.pop_back();
      num.pop_back();
      if(val.back() == -1) {
        val.back() = tmp;
      } else {
        while(val.back() > 0 && tmp > 0) {
          val.back() /= 2;
          tmp--;
        }
      }
    }
  }

  cout << val[0] << endl;
  return true;
}

int main() {

  while(solve()) {}

}









Measured memory_bytes: 3868
#include<stdio.h>
int gcd(int x,int y){
	int r,m;
	if(x < y){
		m=x;
		x=y;
		y=m;
	}
	while(y > 0){
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}
int main()
{
	unsigned long long int a,b,x,n;
	while(scanf("%lld%lld",&a,&b)!=EOF){
		x=gcd(a,b);
		printf("%lld ",x);
		n=a/x*b;
		printf("%lld\n",n);
	}
	return 0;
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var vlist = Console.ReadLine().Split(' ').Select(double.Parse);

            var output = vlist.OrderBy(v => v).Aggregate((l, r) => (l + r) * 0.5);
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 13396
#include<stdio.h>

int main()
{
	int a,b,c,k;
	int result;
	scanf("%d %d %d %d",&a,&b,&c,&k);
	if(a>=k)
	{
		result=k;
	}
	else
	{
		if((a+b)>=k)
		{
			result=a;
		}
		else
		{
			result=a-(k-a-b);
		}
	}
	printf("%d",result);
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	int ans = 0;
	int lr=0,l=0,r=0;
	rep(i,n){
		string s; cin >> s;
		rep(j,s.size()-1){
			string x;
			x += s[j];
			x += s[j+1];
			if(x=="AB") ans++;
		}
		if(s[0]=='B'&&s[s.size()-1]=='A') lr++;
		else if(s[0]=='B') l++;
		else if(s[s.size()-1]=='A') r++;
	}
//	cout << ans << endl;
//	cout << lr << " " << l << " " << r << endl;
	ans += max(0,lr-1);
	lr = min(lr,1);
	if(l!=0&&lr!=0){
		ans++;
		lr--;
	}else if(r!=0&&lr!=0){
		ans++;
		lr--;		
	}
	ans += min(l,r);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[200010];
int K;

int num[200010];
int p[200010];
vector<int> v;
vector<int> v2;
set<int> U;

signed main(){
	cin>>N>>K;
	REP(i,N){
		cin>>A[i];
		A[i]--;
	}
	num[0]=1;
	int s=A[0];
	while(true){
		num[s]++;
		p[s]=v.size();
		if(num[s]==2){
			break;
		}
		v.push_back(s);
		s=A[s];
	}
	v2.push_back(s);
	s=A[s];
	while(true){
		num[s]++;
		if(num[s]==3){
			break;
		}
		v2.push_back(s);
		s=A[s];
	}
	REP(i,v.size()){
		DEB(v[i])END
	}
	REP(i,v2.size()){
		DEB(v2[i])END
	}
	if(K<=v.size()){
		cout<<v[K-1]+1<<endl;
	}
	else{
		K-=v.size();
		cout<<v2[(K-1+v2.size())%(int)v2.size()]+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 12336