akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int d;cin>>d;
    if(d == 25){
        cout<<"Christmas"<<endl;
    }
    if(d == 24){
        cout<<"Christmas Eve"<<endl;
    }
    if(d == 23){
        cout<<"Christmas Eve Eve"<<endl;
    }
    if(d == 22){
        cout<<"Christmas Eve Eve Eve"<<endl;
    }
    
	return;
}

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

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int N,S;
int main() {
  while (cin >> N && N>0) {
    int sum = 0;
    int largest = 0;
    int smallest = 1000;
    for (int i=0;i<N;++i) {
      cin >> S;
      if (largest < S) {
	largest = S;
      }
      if (smallest > S) {
	smallest = S;
      }
      sum += S;
    }
    cout << (sum-smallest-largest)/(N-2) << endl;
  }
}

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

int main() {
  int64_t A,B,C,K;
  cin>>A>>B>>C>>K;
  int64_t sum=A;
  if(A>=K)sum=K;
  else if((A+B)<K){
    sum-=(K-A-B);
  }
  cout<<sum<<endl;
}



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

int main() {
	ios::sync_with_stdio(false);
	int a, b, n, cnt=0, num[5];
	cin >> a >> b;
	for (; a <= b; a++) {
		n = a;
		for (int i = 0; i < 5; i++) {
			num[i] = n%10;
			n = n / 10;
		}
		if ((num[0]==num[4]) && (num[1] == num[3])){
			cnt++;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define bug cout<<"--------------"<<endl
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=1e9;
const ll llf=1e18;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,k;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>k;
	if(k&1){
		ll d=n/k;
		cout<<d*d*d<<endl;
	}else{
		if(n<k/2){
			cout<<0<<endl;
			return 0;
		}
		ll ans=0,ret=0;
		for(int i=k;i-k/2<=n;i+=k){
			ans++;
			ret++;
		}
		ans=ans+(ans-1)*ans*3;
		if(ret>=3) ans+=ret*(ret-1)*(ret-2);
		ret=n/k;
		ans+=ret*ret*ret;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto N = readln.chomp.to!long;
    if (N == 1) {
        writeln(1);
        return;
    }
    auto T = new long[][N];
    foreach (_; 1..N) {
        auto uv = readln.split.to!(long[]);
        auto u = uv[0]-1;
        auto v = uv[1]-1;
        T[u] ~= v;
        T[v] ~= u;
    }

    long r;
    foreach (i; 0..N) {
        sort(T[i]);
        if (T[i][0] > i) {
            r += (N-i) * (i+1); 
        } else {
            long prev_j = -1, d = 1;
            foreach (j; T[i]) if (j < i) --d;
            foreach (j; T[i]) if (j < i) {
                r += (j - prev_j) * (N-i) * d;
                prev_j = j;
                ++d;
            }
            r += (N-i) * (i-prev_j);
        }
    }
    writeln(r);
}

Measured memory_bytes: 31084
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

bool check(string s) {
    int N = s.length.to!int;
    debug {
        writeln(s[0 .. (N - 1) / 2]);
        writeln(s[(N + 1) / 2 .. $]);
    }
    return isPal(s) && isPal(s[0 .. (N - 1) / 2]) && isPal(s[(N + 1) / 2 .. $]);
}

bool isPal(string s) {
    return s == s.retro.to!string;
}

void main() {
    string s;
    scan(s);

    yes(check(s));
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdint>

using namespace std;

template<class T>
T read()
{
    T value;
    std::cin >> value;
    return value;
}
 
template<class F>
void times_do(size_t n, F func)
{
    for(size_t i = 0; i < n; ++i) func();
}
 
template<class T>
vector<T> reads(size_t n)
{
    vector<T> a;
    a.reserve(n);
    times_do(n, [&](){
        a.push_back(read<T>());
    });
    return a;
}

int main()
{
    const auto n = read<size_t>();
    /*const auto z = */read<int64_t>();
    const auto w = read<int64_t>();
    const auto a = reads<int64_t>(n);
    
    auto ans_1 = abs(a.at(n-1) - w);
    auto ans_2 = n > 1 ? abs(a.at(n-2) - a.at(n-1)) : 0;
    
    cout << max(ans_1, ans_2) << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque
S = deque(list(input()))
Q = int(input())

flag = False
for _ in range(Q):
    IN = list(map(str,input().split()))

    if IN[0] == "1":
        flag = not flag
        continue

    _,F,C = IN
    if flag:
        if F == "1":
            S.append(C)
        else:
            S.appendleft(C)
    else:
        if F == "1":
            S.appendleft(C)
        else:
            S.append(C)

if flag:
    print(*reversed(S),sep="")
else:
    print(*S,sep="")

Measured memory_bytes: 12512
#include <cstdio>
#include <algorithm>
#define MAXN 55
bool cmp(int x, int y) {
	return x > y;
} 
int a[MAXN];
int main() {
	int n, k, stick, sum = 0;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++) 
		scanf("%d", &a[i]);
	std::sort(a+1, a+1+n, cmp);
	for(int i = 1; i <= k; i++)
		sum += a[i];
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,a[N],v[N];
bool test(int mid){
	for (int i=1;i<=2*n-1;i++) v[i]=(a[i]>mid);
	int ll=1,rr=2*n-1;
	for (int i=1;i<=2*n-2;i++)
	if (v[i]==v[i+1]){
		if (i>=n) rr=min(rr,i);
		if (i<n) ll=max(ll,i+1);
	}
	//printf("test(%d): ll=%d rr=%d\n",mid,ll,rr);
	return n-ll<rr-n?v[ll]:v[rr];
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=2*n-1;i++) scanf("%d",&a[i]);
	int l=1,r=2*n-1;
	while (l<r){
		int mid=(l+r)>>1;
		if (test(mid)) l=mid+1;else r=mid;
	}
	printf("%d\n",l);
	return 0;
}

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

using namespace std;

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

    int ans = 0;
    string V = "000";
    for(int i = 0; i < 1000; ++i){
        int Vindex = 0;
        for(int j = 0; j < N; ++j){
            if(S[j] == V[Vindex]){
                Vindex++;
            }
            if(Vindex == 3){
                ans++;
                break;
            }
        }
        int Vint = stoi(V);
        Vint++;
        if(Vint <= 9){
            V = "00" + to_string(Vint);
        }else if(Vint <= 99){
            V = "0" + to_string(Vint);
        }else{
            V = to_string(Vint);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CADDi_D solver = new CADDi_D();
        solver.solve(1, in, out);
        out.close();
    }

    static class CADDi_D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long a[] = new long[n];
            boolean flag = false;
            for (int i = 0; i < n; i++) {
                if (in.nextLong() % 2 == 1) {
                    flag = true;
                }
            }

            out.print(flag ? "first" : "second");


        }

    }
}



Measured memory_bytes: 60108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var csl = Console.ReadLine();
            var N = int.Parse(csl.Split(' ')[0]);
            var K = int.Parse(csl.Split(' ')[1]);

            var array = new List<int>();
            csl = Console.ReadLine();
            foreach(var n in csl.Split(' '))
            {
                array.Add(int.Parse(n));    
            }

            array.Sort((a, b) => b - a);

            int hebi_size = 0;
            for(var i = 0; i < K; i++)
            {
                hebi_size += array[i];
            }

            Console.WriteLine(hebi_size);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	int n;
	cin>>n;
	vector<int>v(n);
	
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		v.at(i)=a;
	}
	
	int a=v.at(0);
	if(a==2){
		cout<<"1"<<endl;
	}
	else{
		for(int i=0;i<n;i++){
			a=v.at(a-1);
			if(a==2){
				cout<<i+2<<endl;
				break;
			}
			else if(i==n-1){
				cout<<"-1"<<endl;
				break;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int p, l ,r;};
struct Node T[MAX];
int n;

void preParse(int u)
{
if ( u == NIL ) return;
printf(" %d",u);
preParse(T[u].l);
preParse(T[u].r);
}

void inParse(int u)
{
if(u == NIL) return;
inParse(T[u].l);
printf(" %d",u);
inParse(T[u].r);
}

void postParse(int u){
if( u == NIL ) return;
postParse(T[u].l);
postParse(T[u].r);
printf(" %d",u);
}
int main(){
int i,v,l,r,root;

scanf("%d",&n);
for(i = 0;i < n;i++)
{
T[i].p = NIL;
}
 for( i = 0; i < n; i++){
 scanf("%d %d %d",&v, &l ,&r);
 T[v].l = l;
 T[v].r = r;
 if(l != NIL) T[l].p = v;
 if(r != NIL) T[r].p = v;
}
  for(i = 0;i < n;i++)
  if(T[i].p == NIL)
  root = i;
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 1856
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

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

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;


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

    map<int, int> mp;
    rep(i, n) mp[p[i]] = i;
    sort(p.rbegin(), p.rend());
    
    multiset<int> s;
    s.insert(-1);
    s.insert(-1);
    s.insert(n);
    s.insert(n);
    
    ll ans = 0;

    rep(i, n) {
        auto itr = s.insert(mp[p[i]]);
        int mid = mp[p[i]];
        itr++;
        int r1 = *itr;
        itr++;
        int r2 = *itr;
        itr--; itr--; itr--;
        int l1 = *itr;
        itr--;
        int l2 = *itr;
        ans += (ll)(r2 - r1) * (ll)(mid - l1) * (ll)p[i];
        ans += (ll)(r1 - mid) * (ll)(l1 - l2) * (ll)p[i];
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 9984
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (a<=b){
            for (int i=0;i<b;i++){
                System.out.print(a);
            }
        }else if (a>b){
            for (int i=0;i<a;i++){
                System.out.print(b);
            }
        }
    }
}

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

int main() {
  int A,B;
  char S[11];
  bool flag=true;
  cin >>A >>B;
  cin >>S;
  for(int i=0;i<=A+B;i++){
    if(i==A){
      flag&=(S[i]=='-')?true:false;
    }
    else{
      flag&=(S[i]<='9'&&S[i]>='0')?true:false;
    }
  }
  if(flag){
   cout <<"Yes"; 
  }
  else{
    cout <<"No";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[10],b[10],c[10];

int main(){

    for(int i=0;i<6;i++)cin >> a[i];
    for(int i=0;i<6;i++)cin >> b[i];
    for(int i=0;i<6;i++)cin >> c[i];

    a[7]=a[0]*3600+a[1]*60+a[2];
    a[8]=a[3]*3600+a[4]*60+a[5];
    a[9]=a[8]-a[7];

    b[7]=b[0]*3600+b[1]*60+b[2];
    b[8]=b[3]*3600+b[4]*60+b[5];
    b[9]=b[8]-b[7];

    c[7]=c[0]*3600+c[1]*60+c[2];
    c[8]=c[3]*3600+c[4]*60+c[5];
    c[9]=c[8]-c[7];

    printf("%d %d %d\n%d %d %d\n%d %d %d\n",a[9]/3600,(a[9]%3600)/60,(a[9]%3600)%60,b[9]/3600,(b[9]%3600)/60,(b[9]%3600)%60,c[9]/3600,(c[9]%3600)/60,(c[9]%3600)%60);

return 0;
}

Measured memory_bytes: 3200
<?php

while (TRUE) {
    fscanf(STDIN, "%d %d", $a, $b);
    if (feof(STDIN)) {
        break;
    }
    $sum = $a + $b;
    for ($i = 0; $sum > 0; $i++) {
        $sum = (int) ($sum / 10);
    }
    echo (string) $i . PHP_EOL;
}

Measured memory_bytes: 6608
#include "bits/stdc++.h"
using namespace std;
#define INF (1 << 29)

struct edge { int to, cost; };
typedef pair<int, int> P;   // firstは最短距離、secondは頂点の番号

const int MAX_V = 3000, MAX_E = 15000;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

int Prev[MAX_V];

void dijkstra(int s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + V, INF);
	fill(Prev, Prev + V, -1);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i<G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
				Prev[e.to] = v;
			}
		}
	}
}

// 頂点tへの最短路
vector<int> get_path(int t) {
	vector<int> path;
	for (; t != -1; t = Prev[t]) path.push_back(t);  // tがsになるまでprev[t]を辿っていく
													 // このままだとt->sの順になっているので逆順にする
	reverse(path.begin(), path.end());
	return path;
}

int main() {
	int H, W;
	cin >> H >> W;
	V = H*W;
	vector<string> s(H);
	for(int i=0; i<H; i++) cin >> s[i];

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if(s[i][j] == '#') continue;
			if (i - 1 >= 0) {
				if(s[i-1][j] == '.') G[i*W + j].push_back(edge{ (i - 1)*W + j, 1 });
			}
			if (j - 1 >= 0) {
				if (s[i][j - 1] == '.') G[i*W + j].push_back(edge{ i*W + (j - 1), 1 });
			}
			if (i + 1 < H) {
				if (s[i+1][j] == '.') G[i*W + j].push_back(edge{ (i + 1)*W + j,1 });
			}
			if (j + 1 < W) {
				if (s[i][j+1] == '.') G[i*W + j].push_back(edge{ i*W + (j + 1), 1 });
			}
		}
	}

	dijkstra(0);

	if (d[V - 1] == INF) {
		cout << "-1" << endl;
		return 0;
	}

	vector<int> path;
	path = get_path(H*W-1);
	//for(auto p : path) cout << p <<" ";
	//cout << endl;

	int ans=0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '.') {
				bool paintable=true;
				for (int k = 0; k < path.size(); k++) {
					if(path[k] == i*W+j) paintable = false;
				}
				//cout << i <<" "<< j <<" :"<< (paintable?"TRUE":"FALSE") << endl;
				if(paintable) ans++;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
// https://qiita.com/e869120/items/eb50fdaece12be418faa

#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    int res = INF;
    int sum = 0;

    for (int i = 0; i < max(x, y) * 2 + 1; i+=2) {
        sum += c * i;
        if (x > i / 2) sum += a * (x - i / 2);
        if (y > i / 2) sum += b * (y - i / 2);
        chmin(res, sum);
        sum = 0;
    }

    cout << res << endl;

    return 0;
}

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

int main()
{
    int n, l;
    cin >> n >> l;
    int ans = 0;
    for(int i = 0; i < n; ++i) ans += l + i;
    if(l >= 0) ans -= l;
    else if(n + l - 1 < 0) ans -= n + l - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
s=input()
ans=0
l=0
r=0
a=0
for i in range(n):
  if s[i]=="(":
    a=a-1
    l=l+1
  else:
    a=a+1
    r=r+1
    if a>ans:
      ans=a
for i in range(ans):
  print("(",end="")
for i in range(n):
  print(s[i],end="")
for i in range(ans+l-r):
  print(")",end="")
print()

Measured memory_bytes: 3064
v[50],p,n,k,X;main(s){for(;n=atoi(gets(v));printf("%d\n",s)){for(p=s=0;p<n;v[++p]=strlen(gets(v+n)));for(;n;){n=0,p=++s;for(k=261096;k/=8;n+=X)for(X=k&7;X>0;X-=v[p++]);}}}

Measured memory_bytes: 532
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s, t; cin >> s >> t;
    ll a, b; cin >> a >> b;
    string u; cin >> u;

    if(s == u){
        cout << a - 1 << " " << b << endl;
    }
    else{
        cout << a << " " << b - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>

#pragma GCC optimize("O3")

using namespace std;
using ll = long long;

#define rep(i, n) for(ll i = 0, l##_len = (n); i < l##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i <= ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i >= ll(b); --i)
#define loop while(true)
#define asort(array, size) std::sort(array, array + size)
#define cauto const auto&
#define bit(n) (1LL << (n))

int main()
{
    int L, R, d;
    cin >> L >> R >> d;
    int count = 0;
    for (int i = L; i <= R; ++i) {
        if (i % d == 0) ++count;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

#define  MOD 1000000007

ll modncr(ll n, ll r){
  auto modbeki = [](ll x, ll nn){
    ll res = 1;
    while(nn > 0){
      if(nn & 1) res = res * x % MOD;
      x = x * x % MOD;
      nn >>= 1;
    }
    return res;
  };

  if(n < r) return 0;
  if(r == 0 || r == n) return 1;
  if(r > n-r) r = n-r;

  ll a = 1, b = 1;
  for(int i = 0; i < r; i++){
    a *= (n - i);
    a %= MOD;
  }
  for(int i = 0; i < r; i++){
    b *= (i + 1);
    b %= MOD;
  }
  ll c = modbeki(b, MOD-2);
  return a * c % MOD;
}

int main(){
  ll N, K;
  cin >> N >> K;
  ll R = N-K;
  for(int i = 1; i <= K; i++){
    ll ans = modncr(R+1, i) * modncr(K-1, i-1) % MOD;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main() {
	int n, ans[100000] = {0};
	scanf("%d", &n);
	for (int x = 1; x <= sqrt(n); x++) {
		for (int y = 1; y <= sqrt(n); y++) {
			for (int z = 1; z <= sqrt(n); z++) {
				ans[x * x + y * y + z * z + x * y + y * z + z * x]++;
			}
		}
	}
	for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 2440
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#define INF 2100000000
using namespace std;
int absint(int a)
{
	return max(a , - a);
}
int main()
{
	static int n, a[100010], b[100010], c[100010], i, j,dp[100010][4];
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[1][1] = a[1];
	dp[1][2] = b[1];
	dp[1][3] = c[1];
	for (i = 2; i <= n; i++)
	{
		dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b[i];
		dp[i][3] = max(dp[i - 1][1], dp[i - 1][2]) + c[i];
	}
	cout << max(dp[n][1], max(dp[n][2], dp[n][3])) << endl;
}

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

using namespace std;

using ll = long long;
using llu = long long unsigned;
using ld = long double;

const int inf = 0x3c3c3c3c;
const ll infl = 0x3c3c3c3c3c3c3c3c;

int main(){
	cin.tie(NULL);
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    if(K == 0) return !printf("%lld", N * N);
    for(int i = K + 1; i <= N; i++){
        ans += (N / i) * (i - K) + max(N % i - K + 1, 0LL);
    }
    printf("%lld", ans);    
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> s(n);
  int i;
  int sum = 0;
  for(i = 0; i < n; i++)
  {
    cin >> s.at(i);
    sum += s.at(i);
  }
  int check = sum;
  if(sum%10 != 0) cout << sum << endl;
  else
  {
    sort(s.begin(), s.end());
    for(i = 0; i < n; i++)
    {
      if(s.at(i)%10 != 0)
      {
        sum -= s.at(i);
        break;
      }
    }
    if(sum == check) cout << 0 << endl;
    else cout << sum << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner scanner = new Scanner(System.in);
    String a = scanner.next();
    String b = scanner.next();
    int num = Integer.parseInt(a + b);

    Double d = Math.sqrt(num);
    String dStr = d.toString();
    String sp[] = dStr.split("\\.");

    if(sp[1].equals("0")) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }

}


Measured memory_bytes: 22740
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define MOD 1000000007

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>

using namespace std;

// clang-format on

main {
  int n, m;
  cin >> n >> m;
  int t[n] = {};
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    t[a - 1]++;
    t[b - 1]++;
  }
  rep(i, n) {
    if (odd(t[i])) {
      cout << "NO" << endl;
      bye;
    }
  }
  cout << "YES" << endl;
  bye;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
  int n,i,c=1;
  char s[100000];
  
  scanf("%d",&n);
  scanf("%s",s);
  
  for(i=0; i<n-1; i++){  
    if(s[i] != s[i+1]){
      c++;
    }
  }
  
  printf("%d",c);
}
    

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int a, b ,c, k;
    
    cin >> a >> b >> c >> k;
    
    int mx = max(max(a, b), c);
    
    cout << pow(2, k) * mx + a + b + c - mx << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*
import java.math.*

private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrint: (String)->Unit = { msg -> System.err.println(msg) }


fun solveD(K:Int):Long {
    var que = LinkedList<Long>()
    for(i in 1L..9L) {
        que.push(i)
    }

    repeat(K-1) {
        val num = que.pollLast()
        val d1 = num%10
        if (d1 == 0L) {
            que.push((num*10+d1))
            que.push((num*10+d1+1))
        } else if (d1 == 9L) {
            que.push((num*10+d1-1))
            que.push((num*10+d1))
        } else {
            que.push((num*10+d1-1))
            que.push((num*10+d1))
            que.push((num*10+d1+1))
        }
    }

    return que.pollLast()
}


fun main(args: Array<String>) {
    val K = readInt()

    val ans = solveD(K)

    println(ans)
}


Measured memory_bytes: 53332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main(){
  ll n;cin>>n;
  ll a[n],b[n];
  vector<pll> c(n);
  for(ll i=0;i<n;i++){
    cin>>a[i]>>b[i];
    c[i]=make_pair(a[i]+b[i],i);
  }
  sort(c.begin(),c.end(),greater<pll>());
  ll ans=0;
  for(ll i=0;i<n;i++){
    ll num=c[i].second;
    if(i%2==0)ans+=a[num];
    else ans-=b[num];
  }
  cout<<ans<<endl;
}
  

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

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

    cout << max(a-b, 0);
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
using R = double;

ll C[51][51];

//組合せのテーブルを作る関数
void comb_table(int N) {
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= i; ++j) {

			//両端は1
			if (j == 0 || j == i) {
				C[i][j] = 1LL;
			}
			//1個上の段の2つを足してつくる。
			else {
				C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
			}
		}
	}
}
int main() {

	//境界値受け取り。
	int N, A, B;
	cin >> N >> A >> B;

	//値を受け取って配列に格納
	const int NMAX = 50;
	ll v[NMAX];

	for (int i = 0; i < N; ++i) {
		cin >> v[i];
	}

	//大きい方から選びたいので、降順に並べ替え。
	sort(v, v + N);
	reverse(v, v + N);

	//考察の通り、大きい方からA時の平均が最大。


	R max_average = 0.0;
	//総和とる。
	for (int i = 0; i < A; ++i) {
		max_average += v[i];
	}
	//Aで割る。
	max_average /= A;
	//平均求まった。

	//A番目に大きい値が配列全体で何個あるか数える。
	//上位がVaだけで埋まっているかも調べる。
	int a_th_val_num = 0, a_th_va_pos = 0;
	for (int i = 0; i < N; i++) {
		if (v[i] == v[A - 1]) {
			a_th_val_num++;
			if (i < A) {
				a_th_va_pos++;
			}
		}
	}


	comb_table(N);
	ll cnt = 0LL;
	//0からA-1までVaで埋まっている場合。
	if (a_th_va_pos == A) {
		for (a_th_va_pos = A; a_th_va_pos <= B; ++a_th_va_pos) {
			cnt += C[a_th_val_num][a_th_va_pos];
		}
	}
	//違う場合。
	else {
		cnt += C[a_th_val_num][a_th_va_pos];
	}

	cout.precision(20);
	cout << fixed << max_average << endl;
	cout << cnt << endl;



	return 0;
}


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

int main()
{
        int n; cin>>n;
        int x[n+1],y[n+1],t[n+1];
        x[0]=y[0]=t[0]=0;

        for(int i=1;i<n+1;i++)
        {
                cin>>t[i]>>x[i]>>y[i];
        }
        bool flag=true;
        for(int i=1;i<n+1;i++)
        {
                int dt=t[i]-t[i-1];
                int dx=abs(x[i]-x[i-1]);
                int dy=abs(y[i]-y[i-1]);

                if(dx+dy>dt) flag=false;
                else if((dx+dy-dt)%2!=0) flag=false;
                if(!flag) break;
        }
        cout<<(flag?"Yes":"No")<<endl;
        return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#define INF 10000000009
using namespace std;
int main() {
	int n, m;
	int c[20];
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> c[i];
	}
	int DP[50001];
	DP[0] = 0;
	for (int i = 1; i <= n; i++) {
		DP[i] = INF;
		for (int j = 0; j < m; j++) {
			if (i - c[j] < 0)continue;
			DP[i] = min(DP[i],DP[i - c[j]] + 1);
		}
	}
	cout << DP[n] << endl;
	return 0;
}


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

int main()
{
    ll a,b,c,ans;
    cin>>a>>b;
    c=a%b; //cout<<c<<endl;
    if(c==0)
    {
        cout<<0<<endl;
        return 0;
    }
    ans=abs(c-b);

    if(ans<a)
        cout<<ans<<endl;
    else
    cout<<a<<endl;

}




Measured memory_bytes: 256
#include<stdio.h>
 
static const int MAX = 500;
static const int INFTY = (1<<21);
 
main(void){
  int n, i, j, e, sum;
  int g[MAX][MAX],d[MAX],pi[MAX],min = INFTY, a, b,v[MAX];
 
  scanf("%d", &n);
 
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      g[i][j] = (e==-1)?INFTY:e;
    }
  }
 
 
  for(i = 0; i < n; i++){
    d[i] = INFTY;
    v[i] = 0; 
    pi[i] = -1;
  }
  d[0] = 0;
   
  while(1){
    b = -1;
    min = INFTY;
 
   
    for(i = 0; i < n; i++){
      if(d[i] < min && !v[i]){ 
    b = i; 
    min = d[i]; 
      }
    }
 
    if(b == -1){
      break; 
    }
    v[b] = 1; 
 
    for(a = 0; a < n; a++){
      if(d[a] >= g[b][a] && !v[a]){
    d[a] = g[b][a];
    pi[a] = b; 
      }
    }
  }
     
 
  sum = 0;
 
  for ( i = 0; i < n; i++ ){
    if ( pi[i] != -1 ) {
      sum = sum + g[i][pi[i]];
    }
  }
 
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 804
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
const double eps = 1e-8, inf = 1e+8;

template<typename T> inline void chmin(T& t, T f){if(t > f)t = f;}

struct Edge {
    int to; double wt; int cap;
    Edge(int to, double wt, int cap):to(to), wt(wt), cap(cap){}
};

int n, m, s, g;

double solve(vector<vector<Edge> >& G){
    double res = inf;
    vector<vector<vector<double> > > mem(n, vector<vector<double> >(n, vector<double>(35, inf)));
    mem[s][s][0] = 0.;
    typedef tuple<double, int, int, int> State;
    priority_queue<State> q;
    for(q.emplace(0., 0, s, s); !q.empty();){
        double t; int v, u, p;
        tie(t, v, u, p) = q.top(); q.pop();
        if(mem[u][p][v] + t < -eps || res + t <= -eps)continue;
        if(u == g && v == 1)chmin(res, -t);
        for(auto e: G[u])if(e.to != p){
            for(int dv=-1; dv<=1; ++dv){
                int nv = v + dv <= 0? 1: v + dv;
                double nt = e.wt / nv - t;
                if(30 < nv || e.cap < nv || mem[e.to][u][nv] <= nt + eps)continue;
                mem[e.to][u][nv] = nt;
                q.emplace(-mem[e.to][u][nv], nv, e.to, u);
            }
        }
    }
    if(inf - res < eps)throw "unreachable";
    return res;
}

int main(){
    while(cin >> n >> m, n|m){
        cin >> s >> g;
        s--; g--;
        vector<vector<Edge> > G(n);
        rep(i, m){
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            x--; y--;
            G[x].emplace_back(y, d, c);
            G[y].emplace_back(x, d, c);
        }
        try{
            cout << fixed << setprecision(5) << solve(G) << '\n';
        }
        catch(const char* mes){
            cout << mes << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 2216
n,m = map(int,input().split())
dic = {}
ls = [1]*(n+1)
ls[0] = 0
ans = 0
dic[1] = 1
for i in range(m):
    a,b = map(int,input().split())
    ls[a] -= 1
    ls[b] += 1
    if dic.get(a,0) != 0:
        if dic.get(b,0) == 0:
            dic[b] = 1
    else:
        if ls[b] == 1:
            dic[b] = 0
for j in range(n+1):
    if ls[j] > 0 and dic.get(j,0) != 0:
        ans += 1
print(ans)

Measured memory_bytes: 19916
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    int X,A; cin >> X >> A;
    if(X < A) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define ull unsigned long long int
#define ll long long
#define vi vector<int>
#define mii map<int,int>
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//#define endl "\n"
#define pb push_back
#define MOD 1e9+7
#define INF 0x3f3f3f3f
//#define show(x) cerr<<x#<<" "<<x<<"\n";
//typedef tree<pair<int,int>,null_type,
//less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
//#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)\
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("O3")
//uncoment for large int requirement

//using boost::multiprecision::cpp_int;
//using namespace _gnu_pbds;
using namespace std;

/*bool isleap(int year)
{
    return (((year % 4 == 0) && (year % 100 != 0)) ||
             (year % 400 == 0));
}

bool isprime(ull n)
{
    if (n <= 1) return false;
    if (n <= 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
vector<int>Primes;

void Sieve(){
	int N = 1e6+1;
	bool isPrime[N];
	fill(isPrime,isPrime+N,true);
	for(int i=2;i*i<=N;i++){
		if(isPrime[i]){
			for(int j=i*i;j<=N;j+=i){
				isPrime[j] = false;
			}
		}
	}
	for(int i=2;i<=N;i++){
		if(isPrime[i])
			Primes.pb(i);
	}
}
ll ipow(ll base, ll exp)
{
    ll result = 1;
    for (;;)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        if (!exp)
            break;
        base *= base;
    }

    return result;
}
for combination
int mul(int x, int y)
{
    return (x * 1ll * y) % MOD;
}

int binpow(int x, int y)
{
    int z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

int inv(int x)
{
    return binpow(x, MOD - 2);
}

int divide(int x, int y)
{
    return mul(x, inv(y));
}

int fact[N];



int C(int n, int k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
//for factorials
    fact[0] = 1;
    for(int i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
        calliing statement should like this
        also keep in mind if the k>=0&&k<=n;
        C(n,k);
        for inverse factorial
        int ifact[N];
        https://www.codechef.com/viewsolution/30286340
            ifact[N-1]=pw(fact[N-1],mod-2);
    for(int i=N-2;i;i--) ifact[i]= mul(ifact[i+1],i+1);
//finding xor upto n ;
int findXOR(int n)
{
    switch(n&3)
    {
    case 0 : return n;
    case 1 : return 1;
    case 2 : return n+1;
    case 3 : return 0;
    }

}
*/
int main()
{//fast_io

ll n;
 cin>>n;
 ll ans =0 ; 
 ans+=(n/500)*1000;
 n=n%500;
 ans+=(n/5)*5;
 cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.sort()
t = 0
i = 0
while True:
    if A[i]<0:
        A[i] = -1*A[i]
        t+=1
        if i==N-1:
            if t%2==0:
                break
            elif t%2==1:
                A[i] = -1*A[i]
                break
    elif A[i]>=0:
        if t%2==0:
            break
        elif t%2==1:
            X = -1*A[i]+A[i-1]
            Y = -1*A[i-1]+A[i]
            if X>=Y:
                A[i] = -1*A[i]
            else:
                A[i-1] = -1*A[i-1]
            break
    i+=1

print(sum(A))

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

template <typename T> T gcd(T a, T b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

template <typename T> T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

void solve() {
    int x;
    cin >> x;

    int happy = 0;
    happy += x / 500 * 1000;
    happy += x % 500 / 5 * 5;

    cout << happy << endl;
}

int main() {
    solve();

    return 0;
}


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

int main(int argc, const char * argv[]) {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    //a<=x<=b,c<=y<=d  x*y
    long s=(long)b*d,t=(long)a*c;
    if(s<t){
        s=t;
    }
    t=(long)a*d;
    if(s<t){
        s=t;
    }
    t=(long)b*c;
    if(s<t){
        s=t;
    }
    cout<<s<<endl;
    
    return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a.at(i);
  }
  int index=0;
  int N=1,s=0;  
  rep(i,n){
    if(a.at(i)==N){
      N++;
      s++;
    }
  }
  if(s==0){
    cout<<-1<<endl;
    return 0;
  }
  cout<<n-s<<endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] a = new int[101];
		int[] b = new int[101];
		ArrayList<Integer> list = new ArrayList<Integer>();
		String s = "";
		int i = 0;
		int count = 0;
		
		while(true){
			s = sc.next();
			if(s.compareTo("0,0")==0) break;
			i = 0;
			while(s.substring(i,i+1).compareTo(",")!=0)i++;
			a[count] = Integer.valueOf(s.substring(0,i));
			b[count] = Integer.valueOf(s.substring(i+1, s.length()));
			if(list.contains(b[count])==false) list.add(b[count]);
			count++;
		}
		Collections.sort(list);
		
		while(sc.hasNext()){
			int n = sc.nextInt();
			for(int j=0;;j++){
				if(a[j]==n){
					i = list.indexOf(b[j]);
					System.out.println(list.size()-i);
					break;
				}
			}
		}
	}	
}

Measured memory_bytes: 17360
hp1,at1,hp2,at2=gets.split.map!(&:to_i)
kai1=0
kai2=0
while hp2>0
  hp2-=at1
  kai1+=1
end
while hp1>0
  hp1-=at2
  kai2+=1
end
if kai1<=kai2
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 14308
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <sstream>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const int mod=1e9+7;
const LL inf=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=1005;

struct Node{
    int pri;
    double v;
    double avg;

    bool operator<(const Node &cmp)const{
        return avg<cmp.avg;
    }
}p[10];

int main() {
    while(~scanf("%d%d%d%d", &p[0].pri, &p[1].pri,&p[2].pri, &p[3].pri)){
        p[0].v=0.25;
        p[1].v=0.5;
        p[2].v=1;
        p[3].v=2;
        for(int i=0;i<4;i++){
            p[i].avg=p[i].pri*1.0/p[i].v;
        }
        sort(p, p+4);
        double all;
        scanf("%lf", &all);
        LL ans=0;
        for(int i=0;i<4;i++){
            LL x=floor(all/p[i].v);
            ans+=x*p[i].pri;
            all-=x*p[i].v;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h> 
int main(void)
{
	int n, m,l, i, j, k;
	long int a[100][100] = { 0 }, b[100][100] = { 0 }, c[100][100] = { 0 };
	scanf("%d %d %d", &n, &m,&l);
	for (i = 0;i < n;i++)
	{
		for (j = 0;j < m;j++)
		{
			scanf("%lld", &a[i][j]);
		}
	}
	for (i = 0;i < m;i++)
	{
		for (j = 0;j < l;j++)
		{
			scanf("%lld", &b[i][j]);
		}
	}
	for (i = 0;i < n;i++)
	{
		for (j = 0;j < l;j++)
		{
			for (k = 0;k < m;k++)
			{
				c[i][j] +=a[i][k] * b[k][j];
			}
		}
	}
	for (i = 0;i < n;i++)
	{
		for (j = 0;j < l;j++)
		{
			printf("%lld", c[i][j]);
			if (j==l-1)
			{
				printf("\n");
			}
			else
			{
				printf(" ");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int i;
    long long arr[90] = {0};
    arr[0] = 2;
    arr[1] = 1;
    for(i=2; i<=n; i++){
        arr[i] = arr[i-1] + arr[i-2];
    }
    cout << arr[n] << endl;
    return 0;
}

Measured memory_bytes: 3676
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main ()
{
    size_t n;
    cin >> n;
    set<string> prize;
    string name;
    for (int i = 0; i < n; ++i) {
        cin >> name;
        prize.insert (name);
    }
    cout << prize.size ();
}


Measured memory_bytes: 19180
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,m,c;
    ll a[30][30],b[30];
    std::cin >> n>>m>>c;
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            std::cin >> a[i][j];
        }
    }
    ll result = 0;
    
    for (int i = 0; i < n; i++) {
        ll sum = c;
        for (int j = 0; j < m; j++) {
            sum += a[i][j]*b[j];
        }
        if(sum>0){
            result++;
        }
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
        char[] s = new char[S.length()];
        for(int i=0; i<S.length(); i++){
          s[i] = S.charAt(i);
        }
        
        String ans = "";
        for(int i=0; i<S.length(); i++){
          if(s[i] == '0'){
            ans += 0;
          }else if(s[i] == '1'){
            ans += 1;
          }else{
            if(ans.length()>0){
              ans = ans.substring(0, ans.length()-1);
            }
          }
          if(i==S.length()-1){
            System.out.println(ans);
          }
        }
    }
}

Measured memory_bytes: 22736
n, m = map(int, input().split())
h = list(map(int, input().split()))
k = [list(map(int, list(input().split()))) for i in range(m)]

d = [0] * n
for i in range(m):
    d[k[i][0] - 1] = max(d[k[i][0] - 1], h[k[i][1] - 1])
    d[k[i][1] - 1] = max(d[k[i][1] - 1], h[k[i][0] - 1])
    
ans = 0
for i in range(n):
    if h[i] > d[i]:
        ans += 1

print(ans)

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

#define Pi 3.14159265359

int main()
{
	int i, N, L, T[3001];
	scanf("%d %d", &N, &L);
	for (i = 1; i <= N; i++) scanf("%d", &(T[i]));
	
	int j;
	long double t[3001], x = 0.0, y = 0.0;
	for (i = 1; i <= N; i++) t[i] = (long double)T[i] * Pi * 2.0 / L;
	for (i = 1; i <= N - 1; i++) {
		for (j = i + 1; j <= N; j++) {
			x += cos((t[i] + t[j]) / 2) * (N - (j - i) * 2);
			y += sin((t[i] + t[j]) / 2) * (N - (j - i) * 2);
		}
	}
	printf("%.15Lf %.15Lf\n", x * 6.0 / N / (N - 1) / (N - 2), y * 6.0 / N / (N - 1) / (N - 2));
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 256