akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	string sa, sb ,sc;
	cin >> sa >> sb >> sc;
	int ia = 0, ib = 0, ic =0;
	char c = 'a';
	while(ia<sa.length()+1 && ib<sb.length()+1 && ic<sc.length()+1){
		switch(c){
			case 'a':
				if(ia==sa.length()){
					cout << "A\n";
					return 0;
				}
				c=sa[ia];
				++ia;
			break;
			case 'b':
				if(ib==sb.length()){
					cout << "B\n";
					return 0;
				}
				c=sb[ib];
				++ib;
			break;
			case 'c':
				if(ic==sc.length()){
					cout << "C\n";
					return 0;
				}
				c=sc[ic];
				++ic;
			break;
		}
	}

	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll A, B;
	cin >> A >> B;
	if(A+B<10) cout << A+B << endl;
	else cout << "error" << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author houghstc
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <cstring>
#include <climits>

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

const int MOD = 1e9+7;

class DFriends {
public:
    vector<int> parents;
    vector<int> cnts;
    int res = 1;

    int find(int num)
    {
        if(parents[num] == num)
            return num;
        else
            return parents[num] = find(parents[num]);
    }

    void merge(int u, int v)
    {
        int p1 = find(u), p2 = find(v);
        //cout << u << ", " << v << ", p1: " << p1 << ", p2: " << p2 << endl;
        if(p1 != p2)
        {
            parents[p1] = p2;
            cnts[p2] += cnts[p1];
            res = max(res, cnts[p2]);
            //cout << "res ; " << res << endl;
        }
    }

    void solve(std::istream& in, std::ostream& out) {
        int n, m;
        in >> n >> m;
        parents = vector<int>(n+1);
        cnts = vector<int>(n+1, 1);
        for(int i = 1; i <= n; ++i)
        {
            parents[i] = i;
        }

        for(int i = 1; i <= m; ++i)
        {
            int a, b;
            in >> a >> b;
            merge(a, b);
        }

        out << res << endl;
    }
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    DFriends solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] S = Console.ReadLine().Split(' ');

            if (long.Parse(S[2]) > long.Parse(S[0]))
            {
                if (long.Parse(S[2]) > long.Parse(S[0]) + long.Parse(S[1]))
                {
                    Console.WriteLine("0 0");
                }
                else
                {
                    Console.WriteLine("0 " + (long.Parse(S[0]) + long.Parse(S[1]) - long.Parse(S[2])).ToString());
                }
            }
            else
            {
                Console.WriteLine((long.Parse(S[0]) - long.Parse(S[2])).ToString() + " " + S[1]);
            }
        }
    }
}


Measured memory_bytes: 11092
def main():
    n, k = list(map(int, input().split()))
    expect = 0
    for x in range(1, n + 1):
        if x > k - 1:
            expect += 1 / n
            continue
        n2w = 1
        for j in range(1, 100000):
            if x * (2**j) >= k:
                n2w = j
                break
        # print(f'n: {n} k: {k} x: {x} n2w: {n2w}')
        expect += (1 / n) * ((1 / 2) ** n2w)

    print(expect)


main()

Measured memory_bytes: 3060
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cout << double((n+1)/2)/n << "\n";
}



Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      if (n == 0) {
        break;
      }
      int[] as = new int[n];
      for (int ii = 0; ii < n; ii++) {
        as[ii] = scanner.nextInt();
      }
      int count = 0;
      int end = n;
      while (end != 0) {
        for (int ii = 0; ii < end - 1; ii++) {
          if (as[ii] > as[ii + 1]) {
            as[ii] = as[ii] + as[ii + 1];
            as[ii + 1] = as[ii] - as[ii + 1];
            as[ii] = as[ii] - as[ii + 1];
            count++;
          }
        }
        end--;
      }
      System.out.println(count);
    }
  }
}

Measured memory_bytes: 21052
N, M, X = map(int, input().split())
S = []
for i in range(N):
    S.append(list(map(int, input().split())))

lst = []
for i in range(2**N):
    lst.append(str(bin(i)))
    lst[i] = lst[i][2:]
    lst[i] = lst[i].zfill(N)

lst_res = []

for j in lst:
    res = [0]*(M+1)
    for k in range(N):
        if j[k] == "0":
            pass
        else:
            res = [x+y for (x,y) in zip(res,S[k])]
    for l in range(1,M+1):
        if res[l] < X:
            break
    else:
        lst_res.append(res[0])

if lst_res == []:
    print(-1)
else:
    print(min(lst_res))

Measured memory_bytes: 9368
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
int main() {
  int n, r;
  cin >> n >> r;
  if (n >= 10)
    cout << r << endl;
  else {
    cout << r + 100 * (10 - n) << endl;
  }
}

Measured memory_bytes: 3564
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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


int main()
{
	int n, m, a[300][300], ans;
	bool f[300];

	cin >> n >> m;

	ans = n;
	REP(i, m){
		f[i] = true;
	}

	REP(i, n){
		REP(j, m){
			cin >> a[i][j];
			a[i][j]--;
		}
	}

	int idx[300] = {};

	REP(i, m - 1){
		map<int, int> mp;

		REP(j, n){
			while(!f[a[j][idx[j]]]){
				idx[j]++;
			}
			mp[a[j][idx[j]]]++;
		}

		int mx = -1, id = 0;
		for(auto x : mp){
			if(mx < x.second){
				mx = x.second;
				id = x.first;
			}
		}

		// cout << mx << ' ' << id << endl;
		ans = min(ans, mx);
		f[id] = false;
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int dot(int x1, int y1, int x2, int y2) {
    return x1 * x2 + y1 * y2;
}
i64 s, t, u, v;
int solve() {
    i64 x, y;
    cin >> x >> y;
    x -= s;
    y -= t;
    double d = double(dot(x, y, u, v)) / dot(u, v, u, v);
    double p = d * u - x, q = d * v - y;
    printf("%.12f %.12f\n", x + 2 * p + s, y + 2 * q + t);
}
int main() {
    cin >> s >> t >> u >> v;
    u -= s;
    v -= t;
    int q;
    cin >> q;
    while (q--) solve();
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
const int maxN = 2e5 + 7;
typedef long long LL;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

int n;
int a[maxN];

int main() {

	n = ri();
	rep (i, 1, n) a[i] = ri();
	int sum = 0;
	LL res = 0;
	for (int l = 1, r = 1; l <= n; ) {
		for (; r <= n && (sum & a[r]) == 0; ++r) sum |= a[r];
		res += r - l;
		sum ^= a[l++];
	}
	printf("%lld\n", res);

	return 0;
}


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


int main() {
    int N;
    ll A;
    cin >> N;
    priority_queue<int> pq;
    rep(i,N) {
        cin >> A;
        pq.push(A);
    }
    ll ans = pq.top();
    pq.pop();
    if (N > 2) {
        rep(i,(N-2)/2) {
            ans += 2 * pq.top();
            pq.pop();
        }
        if ((N-2) % 2 == 1) {
            ans += pq.top();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4248
using System;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string result = "";
            for (int i = 0; i < s.Length; i += 2)
            {
                result += s[i];
            }
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 34772
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int N = 3000;
		int x = 0;
		int y = 0;
		Scanner scan = new Scanner(System.in);
		for (int i = 0; i < 3000; i++) {
			x = scan.nextInt();
			y = scan.nextInt();
			if (x != 0 || y != 0) {
				if (x < y) {
					System.out.println(x + " "+ y);
				} else {
					System.out.println(y + " " + x);
				}
			} else
				break;
		}
	}

}

Measured memory_bytes: 35424
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-02 22:39:28
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<(x)>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int ans;
    if (n % 2 == 0) ans = n;
    else ans = 2*n;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<deque>
#define jio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
//#define mp make_pair
#define pb push_back
#define lld long long int
#define clr clear()
#define ff first
#define ss second
#define N 1000005
//#define M 1000
#define endl '\n'
#define c_s_b() __builtin_popcount()

#define sze 10000009
#define pii pair<int,int>
#define big 100009
#define int long long

using namespace std;

int n,m;
vector<int>v1;
int ht[big];
 int dp[big];

int fun(int step){

   if(step>=n){
       return INT_MAX;
   }
   if(dp[step]!=-1){
       return dp[step];
   }
   if(step==n-1){
     return 0;
   }
     dp[step]=min((((step+1)<n)?abs(ht[step+1]-ht[step]):INT_MAX)+fun(step+1),(((step+2)<n)?abs(ht[step+2]-ht[step]):INT_MAX)+fun(step+2));
    // cout<<d<<endl;
    return dp[step];

}


int32_t main(){
   jio;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>ht[i];
    }
     memset(dp,-1,sizeof(dp));
    int minm_cst=fun(0);


    cout<<minm_cst<<endl;






    return 0;


}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

int getcost(int a,int b){
    return abs(a-b)*abs(a-b);
}

int N;
#define MAXN 100
int X[MAXN];
int main(){
    cin >> N;
    rep(i,N)cin >> X[i];
    int mini = 1000000000;
    for(int i=1;i<=100;i++){
        int cost = 0;
        for(int j=0;j<N;j++){
            cost += getcost(X[j],i);
        }
        if(cost < mini)mini = cost;
    }
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,l,i,j;
	char s[100][101];
	char box[101];
	scanf("%d %d",&n,&l);
	for(i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(strcmp(s[i],s[j])>0){
				strcpy(box,s[i]);
				strcpy(s[i],s[j]);
				strcpy(s[j],box);
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s",s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
from collections import deque
k = int(input())

e = [[] for i in range(k)]
for i in range(k):
    e[i].append(((i+1)%k,1))
    if i*10%k != i:
        e[i].append(((i*10)%k,0))

d = [-1]*k
d[1] = 0
q = deque([])
q.append((1,0))
while q:
    now,dis = q.popleft()

    for nex,cost in e[now]:
        if d[nex] == -1 or d[nex] > dis+cost:
            d[nex] = dis+cost
            if cost == 0:
                q.appendleft((nex,dis))
            else:
                q.append((nex,dis+1))

print(d[0]+1)

Measured memory_bytes: 38428
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int mat[20][2]={};
int out[20]={};
int mot[20]={};
int rot[20]={};

int get(int num, int keta){
    REP(i,keta){
        int flag = num%2;
        out[i]=mat[i][flag];
        mot[i]=mat[i][flag];
        rot[i]=flag;
        num/=2;
    }
    sort(out,out+keta);
}

int main(){
    int n;
    int a,b;
    int visited[20]={};
    int rotate[20]={};
    int min = 100000;
    scanf("%d",&n);
    REP(i,n){
        scanf("%d",&a);
        mat[i][0]=a;
    }
    REP(i,n){
        scanf("%d",&b);
        mat[i][1]=b;
    }
    REP(i,2<<(n-1)){
        get(i,n);
        REP(j,20)visited[j]=0;
        REP(j,20)rotate[j]=0;
        int time=0;
        REP(j,n){
            int now=0;
            int num=out[j];
            int count=0;
            while(now<n){
                if(visited[now]==0 && mot[now]==num && rot[now]==(count%2+rotate[now])%2){
                    visited[now]=1;
                    time += count;
                    break;
                }
                else if(visited[now]==1){
                    now++;
                }
                else{
                    rotate[now] = 1-rotate[now];
                    now++;
                    count++;
                }
            }
        }
        int flag=1;
        REP(j,n)if(visited[j]==0)flag=0;
        if(flag==1)if(min>time)min=time;

        //REP(j,n)printf("%d,",out[j]);
        //if(flag)printf("   %d###\n",time);
        //else printf("   -1###\n");
    }
    if(min==100000)printf("-1\n");
    else printf("%d\n",min);
    return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = max(0, c-(a-b));
    cout << ans << endl;
    return 0;
}

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

int main()
{
  char s[30];
  scanf("%s",s);
  int n=strlen(s);
  int b[26];
  for(int i=0;i<26;i++)b[i]=n+1;
  for(int i=0;i<n;i++){
    b[s[i]-'a']=i;
  }
  bool F=0;
  for(int i=n;i>=0;i--){
    int c=(i==n?0:s[i]-'a'+1);
    while(c<26&&b[c]<i)c++;
    if(c<26){
      s[i]='a'+c;
      s[i+1]=0;
      printf("%s\n",s);
      F=1;
      break;
    }
  }
  if(!F)puts("-1");
  return 0;
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> ids(M + 1);
  vector<vector<pair<int, int*>>> cache(N + 1);
  for (int city = 1; city <= M; ++city) {
    int P, Y;
    cin >> P >> Y;
    ids[city].first = P;
    cache[P].emplace_back(Y, &ids[city].second);
  }

  for (auto&& years : cache) {
    sort(years.begin(), years.end(), [](auto&& lhs, auto&& rhs) {
      return lhs.first < rhs.first;
    });
    int cnt = 0;
    for (auto p : years) {
      *p.second = ++cnt;
    }
  }

  for (int city = 1; city <= M; ++city) {
    auto&& p = ids[city];
    cout << setw(6) << setfill('0') << p.first
         << setw(6) << setfill('0') << p.second << '\n';
  }
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin>>S;
    for(int i=0;i<2;i++){
        if(S.at(i)!=S.at(i+1)){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int maxA = 0;
		int minB = Integer.MAX_VALUE;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			if (a > maxA) {
				maxA = a;
				minB = b;
			}
		}

		System.out.println(maxA + minB);
		sc.close();
	}

}


Measured memory_bytes: 63660
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

import itertools
import math

path = 0
for ptn in itertools.permutations(range(n)):
    for i, j in zip(ptn, ptn[1:]):
        path += ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) ** 0.5
ans = path / (math.factorial(n))

print(ans)

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

using namespace std;

#define PROBLEM "A"

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)

int main(int argc, char const *argv[])
{
	#ifdef DBG
	freopen(PROBLEM ".in", "r", stdin);
	freopen(PROBLEM ".out", "w", stdout);
	#endif

	int N;
	while(cin >> N){
		cout << pow(N, 3)<<endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

const int N=2e5+5;

ll n,a[N],ans;

int main()
{
    cin >> n;
    for (int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    sort(a,a+n,greater<int>());
    int cnt=n-2;
    ans=a[0];
    if (cnt)
    for (int i=1;i<n;i++)
    {
        if (cnt>1){ans+=2*a[i];cnt-=2;}
        else if (cnt){ans+=a[i];break;}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
  int x[100];
  bool flag = true;
  cin >> N;
  for(int i=0; i < N;i++){
  cin >> x[i];
  }
  for(int i =0; i < N; i++){
    if(x[i] % 2 == 0){
    if(x[i] % 3 != 0 && x[i] % 5 != 0)
      flag = false;
    }
    
       }
  if(flag == true)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
 
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, k, a, cnt[200001];
 
int main(int argc, char **argv) {
	cin >> n >> k;
	CLEAR(cnt);
	REP(i, n) {
		cin >> a;
		++cnt[a];
	}
	sort(cnt, cnt+n+1);
	reverse(cnt, cnt+n+1);
	ll res = 0;
	FOR(i, k, n+1) res += cnt[i];
	cout << res << endl;
	return 0;
}
 

Measured memory_bytes: 1920
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int main()
{
	while(1) {
		string s;
		getline(cin, s);
		if (s.size() == 1 && s[0] == '.') break;

		string a;
		rep(i,0,s.size()) {
			if (s[i] == '(') a += '(';
			if (s[i] == ')') a += ')';
			if (s[i] == '[') a += '[';
			if (s[i] == ']') a += ']';
		}
		//debug(a);
		while (a.size() >= 2) {
			bool update = false;
			rep(i,0,a.size()-1) {
				if ((a[i] == '(' && a[i+1] == ')') || (a[i] == '[' && a[i+1] == ']')) {
					a = a.substr(0,i) + a.substr(i+2); 
					update = true;
					//debug(a);
				}
				else if (i == a.size()-2 && update == false) a = "x";
				if (a.size() < 2) break;
			}
		}

		if (a.size() == 0) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl; 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
// const LL     mod = 1e9 + 7;
LL qpow(LL a,LL b,LL mod){LL s=1;while(b>0){if(b&1)s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
// LL gcd(LL a,LL b,LL mod) {return b?gcd(b,a%b):a;}
int dr[2][4] = {1,-1,0,0,0,0,-1,1};
typedef pair<int,int> P;
const int maxn = 3000+10;
LL a[maxn];
// int dp[maxn];
int fac[maxn],invfac[maxn];
int dp[maxn][maxn];
int p;
int mod;
void Add(int &a,int b){
	a += b;
	if(a >= mod)
		a -= mod;
}

int ans[maxn],tmp[maxn];
int main(void)
{
	
	cin>>p;
	invfac[0] = fac[0] = 1;
	for(int i = 1;i < p; ++i)
		fac[i] = fac[i-1]*i%p;
	invfac[p-1] = qpow(fac[p-1],p-2,p);
	// cout<<fac[p-1]<<invfac[p-1]<<endl;
	for(int i = p-2;i > 0;--i)
		invfac[i] = invfac[i+1]*(i+1)%p; 
	// cout<<fac[2]*invfac[2]%p<<endl;
	// for(int i = 0;i < p; ++i)
	// 	cout<<invfac[i]*fac[i]%p<<endl;
	mod = p;
	for(int i = 0;i < p; ++i)
		cin>>a[i];
	dp[0][1] = 1;
	for(int i = 1;i < p; ++i){
		for(int j = 0;j <= p; ++j){
			dp[i][j] =( mod-1ll*i*dp[i-1][j]%mod)%mod;
			if(j) Add(dp[i][j], dp[i-1][j-1]);
			// Add(dp[i][j],mod-1ll* i*dp[i-1][j]%mod);
		}
	}
	// for(int i = 0;i <= p; ++i)
	// 	cout<<dp[p-1][i]<<" ";
	// cout<<endl;
	// cout<<-1*
	for(int i = 0;i < p; ++i){
		if(!a[i]) continue;
		// memcpy()
		for(int j = p-1;j >= 0; --j)
			tmp[j] = (dp[p-1][j+1]+1ll*tmp[j+1]*i%mod)%mod;
		// for(int j = 0;j < p; ++j)
		// 	cout<<tmp[j]<<" ";
		// cout<<endl;
		int  sign = 1;
		if((p-i-1)&1) sign = -1;
		// cout<<((p-i-1)&1)<<" "<<sign<<endl;
		for(int j = 0;j < p; ++j){
			LL t = 1;
				t = t*invfac[i]%mod;
				t = (sign*t*invfac[p-i-1]%mod+mod)%mod;
			// cout<<j<<" "<<tmp[j]<<endl;
			// cout<<t<<endl;
			// cout<<qpow(1*2*3,p-2,p)<<endl;
			// cout<<invfac[i-1]*invfac

			// cout<<t<<endl;
			// cout<<qpow()
			Add(ans[j],t*tmp[j]%mod+mod);
		}
		// cout<<endl;
		// for(int j = 0;j < p; ++j){
		// 	if(i)
		// 		tmp[j] = tmp[j]*invfac[i-1]%mod;
		// 	if(i != p-1)
		// 		tmp[j] = sign*tmp[j]*invfac[p-i-1]%mod;
		// 	// cout<<j<<" "<<tmp[j]<<endl;
			
		// 	Add(ans[j],tmp[j]%mod+mod);
		// }
	}
    
    for(int  i =0;i < p; ++i)
    	cout<<(ans[i]%mod+mod)%mod<<" ";
    cout<<endl;
   // bbbm
   return 0;
}

/*

5 
0 1 0 1 0
*/

Measured memory_bytes: 35584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		out.println(Math.max(a, Math.max(b, c)) - Math.min(a, Math.min(b, c)));
		
		out.flush();
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;

  int sum = 0;
  int ln,rn;
  for(int i=0; i<N; i++)
  {
    cin >> ln >> rn;
    sum += rn-ln+1;
  }
  
  cout << sum << endl;
}

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

bool field[100][100];

int w, h;

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

void bfs(int x, int y) {
  field[y][x] = false;
  for(int i = 0; i < 8; i++) {
    int tx = x+dx[i], ty = y+dy[i];

    if(0 <= tx && tx < w && 0 <= ty && ty < h && field[ty][tx]) {
      bfs(tx, ty);
    }
  }
}

int main() {
  while(cin >> w >> h, w+h) {
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        cin >> field[i][j];
      }
    }

    int ans = 0;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        if(field[i][j]) {
          ans++;
          bfs(j, i);
          /*for(int k = 0; k < h; k++) {
            for(int l = 0; l < w; l++) {
              cout<< field[k][l] << ' ';
            }
            cout<< endl;
          }
          cout << endl;*/
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1232
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  int n, k, i, cou=0, tmp;
  char L[100001];
  scanf(" %s", L);
  for(n=0; L[n] != '\0'; ++n); //文字数

  long long dplw[n], dpeq[n], mod=1e9 + 7;
  dplw[0]=1, dpeq[0]=2;

  for(i=1; i < n; i++){
    if(L[i] == '1'){
      dplw[i]=(dplw[i - 1] * 3 + dpeq[i - 1]) % mod;
      dpeq[i]=dpeq[i - 1] * 2 % mod;
    }else{
      dplw[i]=dplw[i - 1] * 3 % mod;
      dpeq[i]=dpeq[i - 1];
    }
  }
  printf("%lld", (dplw[n - 1] + dpeq[n - 1]) % mod);
}


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

namespace ITP1 {
	class Program {
		public static void Main() {
			int[] input = Console.ReadLine()
				.Split()
				.Select(int.Parse)
				.ToArray();
			int a = input[0], b = input[1], c = input[2];
			if (a < b && b < c) Console.WriteLine("Yes");
			else Console.WriteLine("No");
		}
	}
}



Measured memory_bytes: 9284
#!/usr/bin/env python
# coding: UTF-8

import sys
if sys.version_info[0]<3: input=raw_input

class StandardInput:

    def stdin_string(self):
        self.s=str(input().rstrip())
        return self.s

    def stdin_integer(self):
        self.n=int(input().rstrip())
        return self.n

    def stdin_array(self):
        self.arr=input().rstrip().split()
        return self.arr

    def stdin_integer_array(self):
        self.arr=list(map(int,input().rstrip().split()))
        return self.arr

def test(k,s):
    if len(s) > k:
        return s[:k]+'...'
    else:
        return s

def main():
    obj=StandardInput()
    k=obj.stdin_integer()
    s=obj.stdin_string()
    print(test(k,s))
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 9196
s_format = input()

first2 = int(s_format[0]+s_format[1])

last2 = int(s_format[2]+s_format[3])

#print(first2, last2)


if 0 < first2 < 13 and 0 < last2 < 13:
    print("AMBIGUOUS")
elif 0 < first2 < 13 and last2 > -1:
    print("MMYY")
elif first2 > -1 and 0 < last2 < 13:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 38384
#include <stdio.h>
int main()
{
  int X;
  int B=0;
  int C=0;
  int D=0;
  int E=0;
  scanf("%d",&X);
  
  if(X>=500){
    B=X/500;
    C=X%500;
    D=B*1000+(C/5)*5;
      printf("%d",D);
  }
  else{
      E=(X/5)*5;
      printf("%d",E);
    }
  return 0;
}

Measured memory_bytes: 128
fun main() {
    // 文字列
    var k = readLine()!!
//    val x: String = readLine()!!
    // 数値
//    val int =readLine()!!.toInt()
    // 行
//    val list = readLine()!!.split(" ").map (String::toInt )
//    val (n,d) = readLine()!!.split(" ").map(String::toInt)
//    val xys = List(n) {
////        readLine()!!.split(" ").map(String::toLong)
//        readLine()!!.toDouble()
//    }
    var max=0
    var count = 0
    for (i in k) {
        if (i == 'R') {
            count++
        } else {
            count = 0
        }
        if(count> max){
            max=count
        }
    }
    print(max)
}

Measured memory_bytes: 34448
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define pb push_back
#define inf 1e18
#define mod 1000000007
#define en '\n'
#define ld long double
#define ff first
#define ss second
#define ull unsigned long long 
#define lb lower_bound
#define ub upper_bound
#define fr(a,b,c) for(ll a = b ; a <= c ; ++a )
#define frn(a,b,c) for(ll a = b ; a >= c ; a -- )
#define fra(a,b) for(auto a: b)
#define ms(a) memset(a,0,sizeof a);
#define alla(a) a,a+n
#define allv(a) a.begin(),a.end()
#define size(a) (ll)a.size()
#define getMat(x,n,m,val) vector<vector<ll>>x(n,vector<ll>(m,val))
const ll MAXN = 2e5+5;
#define pii 3.14159265358979323846 
ll pw(ll b, ll r, ll md){
	ll ans = 1;
	while(r){
		if(r&1)ans = (ans*b)%md;
		b = (b*b)%md;
		r>>=1;
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;cin>>n;
	ll ans = 0 ; 
	fr(i,1,n){
		ll div = n/i;
		ans+=(((div)*(div+1))>>1)*i;
	}
	cout<<ans<<en;
	return 0 ;
}

Measured memory_bytes: 3664
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    a,b,x= inpm()
    if a<=x and x<=a+b:
        print('YES')
    else:
        print('NO')
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
//-------------------------------------------------------------------------------

string s;

void input_var(){
    cin >> s;
}
//-------------------------------------------------------------------------------

signed main(){
    cout << fixed << setprecision(10);
    input_var();
    intl len = s.length();
    intl ans[len];
    m0(ans);
    bool f = true;
    rep(i,len){
        intl j = i;
        intl idx = -1;
        for(;(j < len - 1)&&(s[j] == 'R');j++);
        idx = j;
        for(;(j < len)&&(s[j] == 'L');j++);
        intl num = j - i;
        if(!(num%2)){
            ans[idx-1] = num/2;
            ans[idx] = num/2;
        }
        else {
            if((idx-i)%2){
                ans[idx-1] = num/2 + 1;
                ans[idx] = num/2;
            }
            else {
                ans[idx-1] = num/2;
                ans[idx] = num/2 + 1;
            }
        }
        i = --j;
    }
    rep(i,len-1) cout << ans[i] << " ";
    cout << ans[len-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::string days[7] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
std::string S;

int main()
{
  std::cin >> S;

  ll idx = std::find( days, days+7, S )-days;

  std::cout << (7-idx) << std::endl;

  return 0;
}

Measured memory_bytes: 384
import math
N = int(input())
C = [0] * N
S = [0] * N
F = [0] * N

for i in range(N - 1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(N):
    t = 0
    if i == N - 1:
        print(0)
        exit()
    
    # j → j + 1区間の最短時間を求めていく
    for j in range(i, N-1):
        # 駅j+1を出発する時刻は S[j] + F[j] * k となる
        # これがt以上になる最小のkを求める
        k_tmp = math.ceil((t - S[j])/F[j])
        k = max(0,k_tmp)

        t = S[j] + F[j] * k + C[j]
    
    print(t)




Measured memory_bytes: 44508
import sys
s=sys.stdin
f=lambda:s.readline()
while 1:
 n=int(f())
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=f().strip().split()
  d[k]=v
 a=''
 for _ in[0]*int(f()):
  e=f().strip()
  a+=d[e]if e in d else e
 print(a)


Measured memory_bytes: 6480
#include<iostream>
#include<cstring>
#include<string>
#define L 200000
using namespace std;

int main()
{
  char str[L];
  cin >> str;
  int len=strlen(str);
  for(int i=0; i<len; i++){
    if(str[i] == '?'){
      if(len == 1)
        str[i] = 'D';
      else if(i==0){
        if(str[i+1] == 'P' || str[i+1] == '?')
          str[i] = 'D';
        else if(str[i+1] == 'D' || str[i+1] == '?')
          str[i] = 'P';
      }
      else if(i == len-1){
        if(str[i-1] == 'D'|| str[i-1] == 'P' )
          str[i] = 'D';
        else
          str[i] = 'P';
      }
      else if(str[i-1] == 'P' || str[i+1] == 'P')
        str[i] = 'D';
      else
        str[i] = 'P';

    }
  }
  cout << str << '\n';
}

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

int main() {
	float n;
	cin>>n;
	float temp=1000;
	if(temp>=n){
		cout<<(temp-n)<<"\n";
	}
	else{
	 ll div=(ceil( float(n)/float(temp)));
	 temp=div*temp;
	 cout<<(temp-n)<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3876
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for(int i=0; i<3; i++){
			a[i] = sc.nextInt();
		};
		sc.close();
		int k = a[0];
		if(k != a[1]) {
			if(k != a[2]) {
				System.out.println(k);
			} else {
				System.out.println(a[1]);
			}
		} else if(k != a[2]) {
			if(k != a[1]) {
				System.out.println(a[k]);
			} else {
				System.out.println(a[2]);
			}
		}
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
int main(){
	int r,g,b;
    cin >> r >> g >> b ;
	if((100*r+10*g+b)%4==0){
    	cout << "YES" << endl;
    }
	else{
    	cout << "NO" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int Maxn=200000;
const int Maxk=10;
const int Mod=998244353;
int n;
int k;
int l[Maxk+5],r[Maxk+5];
int f[Maxn+5];
void add(int x,int a){
	for(int i=x;i<=n;i+=(i&(-i))){
		f[i]=(f[i]+a)%Mod;
	}
}
int query(int x){
	int ans=0;
	for(int i=x;i>0;i-=(i&(-i))){
		ans=(ans+f[i])%Mod;
	}
	return ans;
}
int query(int l,int r){
	if(r==0){
		return 0;
	}
	return (query(r)-query(l-1)+Mod)%Mod;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++){
		scanf("%d%d",&l[i],&r[i]);
	}
	add(1,1);
	for(int i=2;i<=n;i++){
		int sum=0;
		for(int j=1;j<=k;j++){
			int left=max(1,i-r[j]),right=max(left-1,i-l[j]);
			sum=(sum+query(left,right))%Mod;
		}
		add(i,sum);
	}
	printf("%d\n",query(n,n));
	return 0;
}


Measured memory_bytes: 2512
from collections import defaultdict
n,m = map(int,input().split())
graph = defaultdict(list)
for i in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = defaultdict(int)
next_list = []
for j in graph[1]:
    ans[j] = 1
    next_list.append(j)

target_list = next_list[:]
while True:
    next_list = []
    if len(target_list) == 0:
        break

    for i in target_list:
        for j in graph[i]:
            if j not in ans:
                ans[j] = i
                next_list.append(j)
    target_list = next_list[:]


print('Yes')
for i in range(2,n+1):
    print(ans[i])

Measured memory_bytes: 47388
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
    int H,i,A[MAX+1];
    
    cin >> H;
    for(i=1; i<=H; i++){
        cin >> A[i];
    }
    
    for(i=1; i<=H; i++){
        cout << "node " << i << ": key = " << A[i] << ", ";
        if(parent(i)>=1) cout << "parent key = " << A[parent(i)] << ", ";
        if(left(i)<=H) cout << "left key = " << A[left(i)] << ", ";
        if(right(i)<=H) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }    
    return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>

int main(void)
{
 int a,b,c,n;

 scanf("%d", &n);
 scanf("%d", &a);
 scanf("%d", &b);

 c = n * a;
if(c <= b) printf("%d\n", c);
else printf("%d\n", b);

 return 0;
}


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

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

  int n,m;
  cin >> n >> m;
  n--; m--;
  cout << n * m << endl;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
#define pi acos(-1)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 500000;
Pii s,t,a[N];int n,v[N],mx,f[N];
void lisan(){
	int len=0;rep(i,1,n)v[++len]=a[i].se;v[++len]=s.se;v[++len]=t.se;
	sort(v+1,v+len+1);
	rep(i,1,n)a[i].se=lower_bound(v+1,v+len+1,a[i].se)-v;//WA
	s.se=lower_bound(v+1,v+len+1,s.se)-v;
	t.se=lower_bound(v+1,v+len+1,t.se)-v;mx=len+2;
}
void add(int p, int x){while(p<=mx)v[p]=max(v[p],x),p+=p&-p;}
int query(int p){int res=0;while(p)res=max(res,v[p]),p-=p&-p;return res;}
int main() {
	read(s.fi);read(s.se);read(t.fi);read(t.se);read(n);
	rep(i,1,n)read(a[i].fi),read(a[i].se);
	if(s>t)swap(s,t);
	/*if(s.fi==t.fi||s.se==t.se){
		double res=(t.fi-s.fi+t.se-s.se)*100;
		rep(i,1,n)if(a[i].fi>=s.fi&&a[i].fi<=t.fi&&a[i].se>=s.se&&a[i].se<=t.se)
			res+=10*pi-20;
		printf("%.13lf",res);
		return 0;
	}*/
	if(s.se>t.se){
		int inf=1e8;
		rep(i,1,n)a[i].se=inf-a[i].se;s.se=inf-s.se;t.se=inf-t.se;
	}
	int d=min(t.fi-s.fi,t.se-s.se);
	sort(a+1,a+n+1);double tmp=(t.fi-s.fi+t.se-s.se)*100.0;lisan();int res=0;
	memset(v,0,sizeof(v));//init used.
	rep(i,1,n)if(a[i].fi>=s.fi&&a[i].fi<=t.fi&&a[i].se>=s.se&&a[i].se<=t.se){
	//	printf("now = %d %d\n",a[i].se,1+query(a[i].se-1));
		f[a[i].se]=1+query(a[i].se-1);res=max(res,f[a[i].se]);
		add(a[i].se,f[a[i].se]);
	}
	double ans=tmp+1.0*res*(5*pi-20);if(res==d+1)ans+=5*pi;
///	printf("%d\n",res);
	printf("%.13lf",ans);
	return 0;
}


Measured memory_bytes: 5248