akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< (int)(n); i++)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define pb(e) push_back(e)
#define foreach(c, i) for(iter(c) i = (c).begin(); i != c.end(); ++i)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int sz = 2010;

int n, m;
long double prob[sz];
long double prob_sum[sz];

long double dp[sz][4];
long double vi_exp[sz], da_exp[sz], vo_exp[sz];

int vi[sz], da[sz], vo[sz];

long double calc_prob(int n, int r){
  long double log_res = 0;
  rep(i, n) log_res += log(i + 1) - log(3.0);
  rep(i, r) log_res -= log(i + 1);
  rep(i, n - r) log_res -= log(i + 1) - log(2.0);
  return exp(log_res);
}

void calc(int param[sz], long double &res, int power, int point){
  dp[0][0] = dp[0][3] = 1, dp[0][1] = dp[0][2] = 0;
  for(int i = 1; i < n; i++){
    int lb = min(m + 1, (power + param[i] - 1) / param[i]); 
    long double win = prob_sum[lb];
    long double lose = 1 - win;
    dp[i][0] = win * dp[i-1][0];
    dp[i][1] = win * dp[i-1][1] + lose * dp[i-1][0];
    dp[i][2] = win * dp[i-1][2] + lose * dp[i-1][1];
    dp[i][3] = lose * dp[i-1][3];
  }
  res = (dp[n-1][0] + dp[n-1][1] + dp[n-1][2]) * point - dp[n-1][3];
}

int main(){
  cin >> n >> m;
  rep(i, n) cin >> vi[i] >> da[i] >> vo[i];
  rep(i, m + 1) prob[i] = calc_prob(m, i);
  prob_sum[0] = 0;
  rep(i, m + 1){
    prob_sum[i+1]= prob_sum[i] + prob[i];
  }
  
  rep(i, m + 1){
    calc(vi, vi_exp[i], i * vi[0], 5);
    calc(da, da_exp[i], i * da[0], 3);
    calc(vo, vo_exp[i], i * vo[0], 2);
  }
  
  /*rep(i, m + 1) cout << vi_exp[i] << (i == m ? '\n' : ' ') << endl;
  rep(i, m + 1) cout << da_exp[i] << (i == m ? '\n' : ' ') << endl;
  rep(i, m + 1) cout << vo_exp[i] << (i == m ? '\n' : ' ') << endl;*/

  long double res = -INF;
  
  rep(i, m + 1)rep(j, m + 1){
    if(i+j<=m) res = max(res,vi_exp[i] + da_exp[j] + vo_exp[m-i-j]);
  }
  printf("%.20Lf\n", res);
  return 0;
}

Measured memory_bytes: 1552
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static int n;

        static void Main(string[] args)
        {
            //[summary]C - Linear Approximation
            n = int.Parse(Console.ReadLine());
            var a = ReadLine();
            var numbers = GetNumbers(a).OrderBy(x => x).ToList();

            int index = GetIndex();
            int b = numbers[index];
            long sadness = CalcSadness(b, numbers);

            Console.WriteLine(sadness);
        }

        static long CalcSadness(int b, List<int> numbers)
        {
            long sadness = 0;

            for (int i = 0; i < n; i++)
            {
                sadness += Math.Abs(numbers[i] - b);
            }

            return sadness;
        }

        static int GetIndex()
        {
            if (n % 2 == 1)
            {
                return (n - 1) / 2;
            }
            else
            {
                return n / 2;
            }
        }

        static IEnumerable<int> GetNumbers(List<int> a)
        {
            for (int i = 0; i < n; i++)
            {
                yield return a[i] - (i + 1);
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 35588
#include<stdio.h>

int main(void){
	int N,M,n,i,j,ans=0,count;
	scanf("%d %d",&N,&M);
	int K[N+1],A[N+1][M+1];
	for(i=1;i<=N;i++) K[i]=0;
	for(i=1;i<=N;i++){
		for(j=1;j<=M;j++) A[i][j]=0;
	}
	
	for(i=1;i<=N;i++){
		scanf("%d",&K[i]);
		for(j=1;j<=K[i];j++){
			scanf("%d",&n);
			A[i][n]=1;
		}
	}
	
	for(j=1;j<=M;j++){
		count=0;
		for(i=1;i<=N;i++){
			if(A[i][j]==1) count++;
		}
		if(count==N) ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var list = new List<string>();

            for (int _ = 0; _ < N; _++)
            {
                list.Add(Console.ReadLine());
            }

            Console.WriteLine(list.Distinct().Count());
        }
    }
}


Measured memory_bytes: 47952
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long inf = 1ll << 61;
const long long mod = 998244353;
typedef pair<int, int> P;
vector<int>G[3],a[3];
int ju[300003];
int kj[300005], kji[300005];

int modpow(int x, int n, int md) {
	if (!n)return 1;
	int res = modpow(x*x%md, n / 2, md);
	if (n & 1)res = res*x%md;
	return res;
}
int comb(int n, int r) {
	if (n < 0 || r<0 || n < r)return 0;
	int ans = kj[n];
	ans = ans*kji[r] % mod;
	ans = ans*kji[n - r] % mod;
	return ans%mod;
}


void kjinit(int n) {
	kj[0] = 1;
	rep(i, n) {
		kj[i + 1] = kj[i] * (i + 1);
		kj[i + 1] %= mod;
	}
	rep(i, n)kji[i] = modpow(kj[i], mod - 2, mod);

}
signed main() {
	int n; cin >> n;
	string s; cin >> s;
	kjinit(s.size() + 1);
	rep(i, 3 * n) {
		if (s[i] == 'R') {
			G[0].push_back(i);
			ju[i] = G[0].size()-1;
		}
		else if (s[i] == 'G') {
			G[1].push_back(i);
			ju[i] = G[1].size()-1;
		}
		else {
			G[2].push_back(i);
			ju[i] = G[2].size() - 1;
		}
		
	}
	int n1 = 0, n2 = 0, n3 = 0;
	int ans = 1;
	rep(i, s.size()) {
		int it[3];
		rep(j, 3)it[j] = G[j][ju[i]];
		sort(it, it + 3);
		if (it[0] == i)n1++;
		if (it[1] == i) {
			ans *= n1 - n2;
			ans %= mod;
			n2++;
		}
		if (it[2] == i) {
			ans *= n2 - n3;
			ans %= mod;
			n3++;
		}
	}
	cout << ans*kj[n]%mod << endl;
}

Measured memory_bytes: 10484
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

int main()
{
    int ABCD;
    if (scanf("%d", &ABCD) < 1) return 0;

    int A = ABCD / 1000;
    int B = (ABCD - 1000 * A) / 100;
    int C = (ABCD - 1000 * A - 100 * B) / 10;
    int D = ABCD - 1000 * A - 100 * B - 10 * C;

    if (A + B + C + D == 7)
    {
        printf("%d+%d+%d+%d=7\n", A, B, C, D);
    }
    else if (A + B + C - D == 7)
    {
        printf("%d+%d+%d-%d=7\n", A, B, C, D);
    }
    else if (A + B - C + D == 7)
    {
        printf("%d+%d-%d+%d=7\n", A, B, C, D);
    }
    else if (A - B + C + D == 7)
    {
        printf("%d-%d+%d+%d=7\n", A, B, C, D);
    }
    else if (A - B + C - D == 7)
    {
        printf("%d-%d+%d-%d=7\n", A, B, C, D);
    }
    else if (A - B - C + D == 7)
    {
        printf("%d-%d-%d+%d=7\n", A, B, C, D);
    }
    else if (A + B - C - D == 7)
    {
        printf("%d+%d-%d-%d=7\n", A, B, C, D);
    }
    else
    {
        printf("%d-%d-%d-%d=7\n", A, B, C, D);
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
char a,b;
cin>>a>>b;
if((a=='H')&&(b=='H'))
{
cout<<"H";
}
 if((a=='D')&&(b=='D')){
cout<<"H";
}

if(((a=='H')&&(b=='D'))|| ((a=='D')&&(b=='H'))){
cout<<"D";
}
}

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

int S[1000], top;

void push(int x){
    S[++top] = x;
}

int pop(){
    top--;
    return S[top+1];
}

int main() {
    int a, b;
    char s[100];
    top = 0;

    while (scanf("%s", s) != EOF){
        if (s[0] == '+'){
            a = pop();
            b = pop();
            push(a + b);
        }

        else if (s[0] == '-'){
            b = pop();
            a = pop();
            push(a - b);
        }

        else if (s[0] == '*'){
            a = pop();
            b = pop();
            push(a * b);
        }

        else {
            push(atoi(s));
        }
    }

    cout << pop() << endl;

    return 0;
}

Measured memory_bytes: 3200
k,x=map(int,input().split(" "))
if x-(k-1)<-1000000:
    mi=0
else:
    mi=x-(k-1)
s=[x-(k-1)]
i=1
while i!=2*k-1:
    if (x-(k-1)+i)>1000000:
        break
    else:

        s.append(x-(k-1)+i)
        i+=1
print(" ".join(map(str,s)))


Measured memory_bytes: 3060
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var tmp = input[1].split(" ");
  var max = 0;
  var ans=0;
  for(var i= 0;i<N;i++){
    if(parseInt(tmp[i])>=max){
      ans++;
      max=parseInt(tmp[i]);
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7496
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int mod = 998244353;
const int MAXN = (int)3e5 + 5;

int fact[MAXN], rev[MAXN];

int n, a, b;

int ans;

ll k;

int binPow(int a, int b, int m = mod) {
    int ret = 1;

    for (; b > 0; b >>= 1) {
        if (b & 1) {
            ret = (ret * 1ll * a) % mod;
        }

        a = (a * 1ll * a) % mod;
    }

    return ret;
}

void pre() {
    fact[0] = 1;

    for (int i = 1; i <= 300000; ++i) {
        fact[i] = (fact[i - 1] * 1ll * i) % mod;
    }

    for (int i = 0; i <= 300000; ++i) {
        rev[i] = binPow(fact[i], mod - 2);
    }
}

void addMod(int &a, int b, int m = mod) {
    a += b;

    if (m <= a) {
        a -= m;
    }
}

int C(int n, int k) {
    if (k < 0 || k > n) {
        return 0;
    }

    return fact[n] * 1ll * rev[k] % mod * rev[n - k] % mod;
}

void solve() {                   
    scanf("%d %d %d", &n, &a, &b);
    scanf("%lld", &k);    

    for (int x = 0; x <= n; ++x) {
        ll left = k - a * 1ll * x;

        if (left < 0) {
            break;
        }

        if (left % b == 0 && left / b <= n) {
            int y = left / b;
            addMod(ans, C(n, x) * 1ll * C(n, y) % mod);
        }
    }  

    printf("%d\n", ans);                          
}

int main() { 
    int tt = 1;

    pre();

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#define INT long long
#define MOD 1000000007
#define oo (1e18)+1
using namespace std;

INT n, a[100010], cnt, p;

int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 1 ; i <= n ; i++ ) cin>>a[i];
    if( a[1] == 1 ) cnt++, swap(a[1], a[2]);
    for(int i = 2 ; i <= n ; i++ )
    {
        if( a[i] == i and a[i+1] == i+1 ) swap(a[i], a[i+1]), i++, cnt++;
        else if( a[i] == i ) swap(a[i], a[i-1]), cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> count = {0,0,0,0};
  for(int i=0; i<n ;i++){
    string judge;
    cin >> judge;
    if(judge=="AC"){
      count.at(0) ++;
    }else if(judge == "WA"){
      count.at(1) ++;
    }else if(judge == "TLE"){
      count.at(2) ++;
    }else if(judge == "RE"){
      count.at(3) ++;
    }
  }
  vector<string> judge_str = {"AC","WA","TLE","RE"};
  for(int i=0; i<4; i++){
    if(count.at(i) == 0){
      cout << judge_str.at(i) << " x " << 0 << endl;
    }else{
    cout << judge_str.at(i) << " x " << count.at(i) << endl;
    }
  }
}
    

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sum[100010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    string S; cin >> S;
    rep(i, n) {
        if(S[i] == 'A' && S[i + 1] == 'C') sum[i + 1]++;
    }
    rep(i, n) sum[i + 1] += sum[i];
    // rep(i, n + 1) cout << sum[i];
    // cout << endl;
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        cout << sum[r] - sum[l] << endl;
    }


    return 0;
}


Measured memory_bytes: 4116
#include <iostream>
#include <string>
#include <vector>
using namespace std;


int main(void) {
    int n, m, c, ans = 0;

    cin >> n >> m >> c;

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

    for (int i = 0; i < n; ++i) {
        int a, sum = c;
        for (int j = 0; j < m; ++j) {
            cin >> a;
            sum += a * b[j];
        }
        if (sum > 0) {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
d=[0]*13
d[0]=1
m=1
mmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13

for c in t:
    e=zero[:]
    for i in (range(10) if c=="?" else[int(c)]):
        for j in range(13):
            #e[(i*mul+j)%13]+=d[j]
            k=(i*m+j)%13
            e[k]+=d[j]
            e[k]%=1000000007
    d=e
    m=10*m%13
print(d[5])



Measured memory_bytes: 42732
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int a,b;
	cin>>a>>b;
	cout<<(a<=b?"unsafe":"safe")<<"\n";
	return 0;
}


Measured memory_bytes: 3612
import numpy as np
n,s = map(int, input().split( ))

a = np.array(list(map(int, input().split( ))))

dp = np.array([[0]*3001 for i in range(n)])
dp[0][0] = 1
dp[0][a[0]] = 1

ans = 0
mod = 998244353
for i in range(1,n):
    dp[i] += dp[i-1]
    dp[i][a[i]:] += dp[i-1][:-a[i]]
    dp[i][0] +=1
    dp[i][a[i]] += 1
    dp[i]%=mod
    ans += dp[i][s]
print(ans%mod)

Measured memory_bytes: 153296
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, M, V, P;
vector<ll> A;
bool check(ll m)
{
  // cout << "m" << m << endl;
  if (m < P)
  {
    return true;
  }
  if (A.at(m) + M < A.at(P - 1))
  {
    return false;
  }
  ll S = 0;
  S += (P - 1) * M;
  S += (N - m) * M;
  for (ll i = P - 1; i < m; ++i)
  {
    S += max(0ll, A.at(m) - A.at(i) + M);
  }
  if (S >= M * V)
  {
    return true;
  }
  return false;
}


int main()
{
  cin >> N >> M >> V >> P;
  A = vector<ll>(N);
  for (ll i = 0; i < N; ++i)
  {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  // cout << "A" << endl;
  // for (ll i = 0; i < N; ++i)
  // {
  //   cout << A.at(i) << ' ';
  // }
  // cout << endl;
  ll l = -1, r = N;
  ll m;
  while (l + 1 != r)
  {
    m = (l + r) / 2;
    if (check(m))
    {
      l = m;
    }
    else
    {
      r = m;
    }
  }
  cout << l + 1 << endl;
  // cout << "l" << l << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n; cin>>n;
  ll x[n]; ll y[n];
  rep(i, n) cin>>x[i]>>y[i];
  double s=0;
  
  for(ll i=0; i<n; i++) {
    for(ll j=0; j<n; j++) {
      s+=sqrt(pow(x[i]-x[j], 2.0)+pow(y[i]-y[j], 2.0));
    }
  }
  
  ll m=1;
  for(ll i=1; i<=n; i++) m*=i;
  ll l=1;
  for(ll i=1; i<n; i++) l*=i;  
  
  cout << fixed << setprecision(10);
  cout << s/n << endl;
  
}

Measured memory_bytes: 256
// Integral

#include <iostream>
using namespace std;

int main() {
	int d;
	while(cin >> d) {
		int x = 0;
		long long S = 0;
		for(int i = 1; i < 600/d; i++) {
			x += d;
			S += d * (x * x);
		}
		cout << S << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
def CODE_festival_2016_A():
    import numpy as np
    N = int(input())
    a = np.array(list(map(int,input().split())))

    ans = 0
    for i in range(N):
        if i == a[a[i]-1]-1:
            ans += 1

    print(int(ans) if ans%2==1 else int(ans/2))


CODE_festival_2016_A()

Measured memory_bytes: 38156
n = gets.to_i
w = []

judge = 0
w << gets.chomp!
(n-1).times do 
    input_str = gets.chomp!

    if w.include?(input_str)
        judge = 1
        w << input_str
    else
        w << input_str
    end

    judge = 1 unless w[-2][-1] == w[-1][0] 

end

if judge == 0
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 3836
#include<iostream>
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>
#include<math.h>
#include"boost/algorithm/string.hpp"

using namespace std;


int main(){


	int a, b = 0;
	string day;
	cin >> day;
	//2019/mm/dd

	if (day[5] == '0' && day[6] < '5'){
		cout << "Heisei" << endl;
	}
	else{
		cout << "TBD" << endl;
	}


	return 0;

	/*Q2*/

	/*Q3*/

		/*Q4*/

		//return 0;
}


Measured memory_bytes: 256
int main() {
	
 	int count = 0;
  	char s[4];
  
  	scanf("%s", s);
  	if(s[0] == '1') ++count;
	if(s[1] == '1') ++count;
	if(s[2] == '1') ++count;
  
  	printf("%d\n", count);
  
	return (0);

}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define IN freopen("perimetric_chapter_1_input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)

#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define i64 long long int
#define ui64 unsigned long long int
#define xx first
#define yy second
//#define ln 17
#define off 2

#define sq(x) ((x)*(x))

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace __gnu_pbds;
using namespace std ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int,int> pii;

#define log 20
#define mod 1000000007LL
#define INF 2000000000
#define maxn 500005

const long double eps = 1e-9 ;

int a[505] , b[505] ;

int main()
{
    int n , m ;

    scanf("%d %d",&m,&n) ;

    int oddcount = 0 ;

    for(int i=1 ; i<=n ; i++)
    {
        scanf("%d",&a[i]) ;
        if( a[i]%2 == 1 ) oddcount++ ;
    }

    if(oddcount>=3)
    {
        printf("Impossible\n") ;
        return 0 ;
    }

    for(int i=1 ; i<=n ; i++)
    {
        if(a[i]%2==1)
        {
            swap(a[1],a[i]) ;
            break ;
        }
    }

    for(int i=2 ; i<=n ; i++)
    {
        if(a[i]%2 == 1)
        {
            swap(a[i],a[n]) ;
        }
    }

    vector <int> b ;

    if(n>1)
    {
        b.pb(a[1]+1) ;
        for(int i=2 ; i<n ; i++)
        {
            b.pb( a[i] ) ;
        }
    }
    else{
        b.pb(1) ;
    }

    if(a[n]!=1)
    {
        b.pb(a[n]-1) ;
    }

    for(int i=1 ; i<=n ; i++) printf("%d ",a[i]) ;
    printf("\n") ;

    printf("%d\n",b.size()) ;
    for(int x:b) printf("%d ",x) ;
    printf("\n") ;

    return 0 ;
}


Measured memory_bytes: 3764
import collections

n  = int(input())
a  = list(map(int, input().split()))
q  = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

# aの中の各要素のカウント
c = collections.Counter(a)

ans = sum(a)
for i in range(q):
  ans += (bc[i][1] - bc[i][0]) * c[bc[i][0]]
  c[bc[i][1]] += c[bc[i][0]]
  c[bc[i][0]]  = 0
  print(ans)

Measured memory_bytes: 107304
#include <bits/stdc++.h>
using namespace std;
int dp[100004][4];
int n=0;
int vacation[100004][4];
int main() {
    cin>>n;
    for(int i=0;i<=100003;++i){
        for(int j=0;j<4;++j)
            dp[i][j]=INT_MIN;
    }
    dp[0][0]=dp[0][1]=dp[0][2]=dp[0][3]=0;
    memset(vacation,0,sizeof(vacation));
    for(int i=1;i<=n;++i){
        for(int j=1;j<=3;++j){
            cin>>vacation[i][j];
        }
    }
    // cout<<endl;
    // for(int i=0;i<=n;++i){
    //     for(int j=0;j<=3;++j){
    //         cout<<vacation[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<endl;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=3;++j){
            vector<int> v;
            for(int k=1;k<=3;++k){
                if(j!=k){
                    v.push_back(dp[i-1][k]);
                }
            }
            dp[i][j]=vacation[i][j]+max(v[0],v[1]);
        }
    }
    // for(int i=0;i<=n;++i){
    //     for(int j=0;j<=3;++j){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<endl;
    int ans=0;
    for(int i=1;i<=3;++i){
        ans=max(dp[n][i],ans);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int N, X;
  cin >> N >> X;
  int A[N], B[N];
  cin >> A[0];
  B[0] = abs(A[0] - X);
  int ans = B[0];
  for(int i=1;i<N;i++){
    cin >> A[i];
    B[i] = abs(A[i] - X);
    ans = __gcd(ans, B[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
long long N, A[87], CurrentMoney = 1000;
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> A[i];
  for (int i = 1; i <= N - 1; i++) {
    long long Stocks = 0;
    if (A[i] < A[i + 1]) Stocks = CurrentMoney / A[i];

    CurrentMoney += (A[i + 1] - A[i]) * Stocks;

  }

  cout << CurrentMoney << endl;

}

Measured memory_bytes: 3624
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
print(*[i + 1 for i in sorted(range(n), key=lambda x: A[x])])

Measured memory_bytes: 68784
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n;
int C;
int s2[100000],t2[100000];
int c2[100000];
typedef pair<int , int > P;
vector<int> s,t;

int x[300000];

int main(){
	cin >> n >> C;
	REP(i,n) {
		cin >> s2[i] >> t2[i] >> c2[i];
	}

	FOR(i,1,C + 1) {
		vector < P > a;
		REP(j,n) {
			if(c2[j] == i) {
				a.pb(P(s2[j],t2[j]));
			}
		}

		sort(a.begin(),a.end());

		REP(j,a.size()) {
			int l = j;
			while(j + 1 < n && a[j].sc == a[j + 1].fi) {
				j++;
			}

			int r = j;

			s.pb(a[l].fi);t.pb(a[r].sc);
		}
	}

	REP(i,s.size()) {
		x[s[i] * 2 - 1]++;x[t[i] * 2 + 1]--;
	}

	FOR(i,2,200001) {
		x[i] += x[i - 1];
	}

	int ans = 0;
	FOR(i,1,200001) {
		ans = max(ans,x[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define amaterasu ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main()
{
    amaterasu
    int n, k;
    cin >> n >> k;
    cout << ceil(float(n)/float(k));
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

	scanf("%d %d %d", &a, &b, &c);
	if(a == b && a == c)puts("No");
	else if(a == b) puts("Yes");
	else if(a == c) puts("Yes");
	else if(b == c) puts("Yes");
	else puts("No");

	return 0;

}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int a[3];

int main(){
  string s;
  cin >> s;
  rep(i,s.size()){
    if(s[i]=='a')a[0]++;
    if(s[i]=='b')a[1]++;
    if(s[i]=='c')a[2]++;
  }
  sort(a,a+3);
  if(a[2]-a[0]>=2)cout << "NO" << endl;
  else cout << "YES" << endl;
return 0;}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	auto A = make_v<int64>(3, 3);
	REP(i, 3) REP(j, 3) cin >> A[i][j];
	int64 N;
	cin >> N;
	vector<int64> b(N);
	REP(i, N) cin >> b[i];
	REP(h, 3) {
	  REP(w, 3) {
	    REP(j, N) {
	      if (A[h][w] == b[j]) {
	        A[h][w] = 0;
	      }
	    }
	  }
	}
	REP(h, 3) {
	  REP(w, 3) {
	    if (h == 1) {
	      if (A[h-1][w] + A[h][w] + A[h+1][w] == 0) {
	        cout << "Yes" << endl;
	        return 0;
	      }
	    }
      if (w == 1) {
        if (A[h][w-1] + A[h][w] + A[h][w+1] == 0) {
          cout << "Yes" << endl;
          return 0;
        }
      }
      if (h == 1 && w == 1) {
        if (A[h-1][w-1] + A[h][w] + A[h+1][w+1] == 0 ||
            A[h-1][w+1] + A[h][w] + A[h+1][w-1] == 0) {
          cout << "Yes" << endl;
          return 0;
        }
      }
	  }
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  int cnt = 0;
  int color = 10000;
  REP(i,n-1){
    if(a[i]==a[i+1]){
      a[i+1] = color;
      color--;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 5005
int main(){
	cin.tie(NULL);
	int n,k,ans=-1,sum,a[N];
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n,greater<int>());
	for(int i=0;i<n;i++){
		sum=0;
		for(int j=i;j<n;j++){
			if(sum+a[j]<k){
				sum+=a[j];
				continue;
			}
			ans=max(ans,j);
		}
	}
	cout<<n-ans-1<<'\n'; 
} 

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

#A
def A():
    a, b, c = LI()
    if a <= c <= b:
        print("Yes")
        return
    print("No")
    return

#B
def B():
    n, m = LI()
    e = defaultdict(int)
    for i in range(1, n + 1): e[i] = 0
    for i in range(m):
        a, b = LI()
        e[a] += 1
        e[b] += 1
    for i in e.values():
        print(i)
    return

#C
def C():
    n, k = LI()
    d = defaultdict(int)
    for i in range(1, 10**5+1): d[i] = 0
    for i in range(n):
        a, b = LI()
        d[a] += b
    for key, valus in d.items():
        k -= valus
        if k <= 0:
            print(key)
            return
    return

#D
def D():
    n, m = LI()
    abc = LIR_(m)
    for i in range(m):
        abc[i][2] = -abc[i][2] - 1
    dist = [inf] * n
    dist[0] = 0
    for _ in range(n - 1):
        for a, b, c in abc:
            dist[b] = min(dist[a] + c , dist[b])
    check = [False] * n
    for _ in range(n):
        for a, b, c in abc:
            if check[a]:
                check[b] = True
            if dist[b] > dist[a] + c:
                check[b] = True
                dist[b] = dist[a] + c
    if check[n - 1]:
        print("inf")
    else:
        print(-dist[n - 1])
    return

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


Measured memory_bytes: 45788
d[1001],c;
main(w,n,i,C,W)
{
  for(;scanf("%d",&w),w;printf("Case %d:\n%d\n%d\n",++c,d[w],i),bzero(d,4004)){
    for(scanf("%d",&n);n--;)
        for(i=w,scanf("%d,%d",&C,&W);i>=W;i--)
            d[i]=fmax(d[i],d[i-W]+C);
    for(i=0;i<w&&d[w]-d[i];)i++;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int fa[100005],k[100005];
int f(int u)
{
	if(u==fa[u])
		return u;
	else
	{
		int t=f(fa[u]);
		k[u]+=k[fa[u]];
		return fa[u]=t;
	}
}
int main()
{
	int i,l,r,d,p,q,n,m;
	cin>>n>>m; 
	for(i=1;i<=n;i++)
	{
		fa[i]=i;
		k[i]=0;
	}
	for(i=1;i<=m;i++)
	{
		cin>>l>>r>>d;
		if(f(l)==f(r))
		{
			if(k[r]-k[l]!=d)
			{
				puts("No");
				return 0;
			}
		}
		else
		{
			p=f(r),q=f(l);
			fa[p]=q;
			k[p]=k[l]-k[r]+d;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 4424
#include<bits/stdc++.h>
using namespace std;
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
long long S;
long long X1;
long long Y1;
long long X2;
long long Y2;
long long X3;
long long Y3;
long long y[100000];
int ys;
int main(){
  rd(S);
  X2 = 1000000000;
  X3 = 1;
  Y3 =divup_L(S,X2);
  Y2 = X2*Y3 - S;
  wt_L(X1);
  wt_L(' ');
  wt_L(Y1);
  wt_L(' ');
  wt_L(X2);
  wt_L(' ');
  wt_L(Y2);
  wt_L(' ');
  wt_L(X3);
  wt_L(' ');
  wt_L(Y3);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// ll S;
// ll X1, Y1, X2, Y2, X3, Y3;
// 
// ll y[1d5]; int ys;
// 
// {
//   rd(S);
// 
//   X2 = 1d9;
//   X3 = 1;
//   Y3 = S /+ X2;
//   Y2 = X2*Y3 - S;
// 
//   wt(X1,Y1,X2,Y2,X3,Y3);
// }


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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}


int main(){

    ll n;
    cin>>n;

    vector<ll> divisors;

    for(ll i = 1; i * i <= n; i++) {

        if(n % i == 0) {
            if(i != 1)divisors.push_back(i);
            if((n / i) != i) divisors.push_back(n / i);
        }

    }

    ll ans = 0;

    for(int i = 0; i < divisors.size(); i++) {
        ll st = n;

        while((st % divisors[i]) == 0) {
            st = st / divisors[i];
        }

        if((st - 1) % divisors[i] == 0) ans++;
    }

    //cout<<ans<<endl;

    ll n1 = n - 1;
    
    for(ll i = 1; i * i <= n1; i++) {

        if(n1 % i == 0) {
            ll d1 = i;
            ll d2 = n1 / i;

            if((n % d1 != 0) || (n % d2 != 0)) {
                ans++;
            }

            if((n % d1 != 0) && (n % d2 != 0)) {
                if(d1 != d2) ans++;
            }
        }

    }

    cout<<ans<<endl;

}


Measured memory_bytes: 384
sd = input()
t = input()
n = len(sd)
m = len(t)
s = []
for i in range(n-m, -1, -1):
  ans = sd[i:i+m]
  for j in range(m + 1):
    if j == m :
      print((sd[:i] + t + sd[i + len(t):]).replace('?','a'))
      exit()
    if ans[j] == '?':
      continue
    elif ans[j] != t[j]:
      break
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

    int x;
    cin >> x;

    int a = 100;
    int ans = 0;
    while(a < x){
        a = (int)((double)a * 1.01);
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    int res = (100 * (n - m) + 1900 * m) * (1 << m);
    cout << res << endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	string S; cin >> S;
	ll ans = 0;
	for(int i = 0; i < (1 << 10); i++) {
		if(i == (1 << S.size() - 1)) break;
		bitset<9> bit(i);
		string num;
		num += S[0];
		ll sum = 0;
		for(int j = 0; j < S.size() - 1; j++) {
			if(!bit.test(j)) num += S[j + 1];
			else {
				sum += stoll(num);
				num = S[j + 1];
			}
		}
		sum += stoll(num);
		ans += sum;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int dp[3003][3003] = {};
    
int main(){
    
    string s, t;cin>>s>>t;
    int n = (int)s.size();
    int m = (int)t.size();
    
    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= m;j++){
            if (i*j == 0) dp[i][j] = 0;
            else if (s[i-1] == t[j-1]) dp[i][j] = 1+dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    
    int i = n;
    int j = m;
    string ans;
    while(i*j > 0 && dp[i][j] > 0){
        while(dp[i][j] == dp[i-1][j]) i--;
        while(dp[i][j] == dp[i][j-1]) j--;
        ans += s[i-1];
        i--;
        j--;
    }
    
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    
    return 0;
}

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

int main(){
  int i,j;
  int N;
  cin >> N;
  vector<int> input(N);
  
  for(i = 0; i < N ; i++)	cin >> input.at(i);
  
  vector<int> mochi(0);  
  int note;
  
  for(j = 0 ; j < N ; j++){
  	for(i = 0 ; i < N - 1; i++){
      if( input.at(i) > input.at(i + 1) ){
    	note = input.at(i);
		input.at(i) = input.at(i + 1);
    	input.at(i + 1) = note;
      }
    }
  }
  
  for(i = 0 ; i < N ; i++){
    mochi.push_back( input.at( input.size() - 1 ) );
	input.pop_back();
    if( mochi.size() > 1 && mochi.at( mochi.size() - 1) == mochi.at( mochi.size() - 2) ){
      mochi.pop_back();
    }
  }
  
  cout << mochi.size() << endl;
  
}        

Measured memory_bytes: 256
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll fun(ll n){
	if(n==1) return(1);
	ll b=fun(n/2);
	return(1+2*b);
}

int main(){
	ll n;
	cin>>n;
	cout<<fun(n);
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    static int p,q,a;

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

	p = sc.nextInt();
	q = sc.nextInt();
	a = sc.nextInt();
	int n = sc.nextInt();

	while(p!=0 && q!=0 && a!=0 && n!=0){
	    
	    System.out.println(solve(n,1,1,0));
	    
	    p = sc.nextInt();
	    q = sc.nextInt();
	    a = sc.nextInt();
	    n = sc.nextInt();
	    
	}
	
    }

    //n:cèÌXebv d:»ÝÌóµ prod:Ï sum:»±ÜÅÌv
    public static int solve(int n, int d, int prod, int sum){
	int count = 0;
	for(int i=d; prod*i<=a; i++){
	    int left = p * (prod * i);//¶Ó
	    int right = sum * i + prod;//EÓ
	    if(left < right * q){continue;}//EÓª¶Óæèå«¯êÎ
	    if(left == right *q){count++; continue;}//EÓÆ¶Óªêvµ½ç
	    if(n ==1){continue;}//TõIíè
	    count += solve(n-1,i,prod*i,right);
	}
	return count;
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int a,b,c;cin>>a>>b>>c;
  if(a==b&&b==c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3544
n=gets.to_i
s=gets.split.map &:to_i
ans=[]
kai=0
(1..n).to_a.each{|i|
ans << (s[i-1]-i)
}
ans.sort!
ha=ans[n/2]
ans.each{|x|kai += (x-ha).abs}
puts kai


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

int main(){
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i=0;i<a.size();i++){
  	cin >> a.at(i);
  }
  
  double ans=0;
  for(int x: a){
    ans += (double)1/x;
  }
  printf("%.10f", 1/ans);
  
  return 0;
}

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

using namespace std;

#define K 600001
#define FOE(i, s, t) for (int i = s; i <= t; i++)

vector<int> nxt[K];
int n, m;

int dfs[K];
vector<int> ans1, ans2;

void DFS(int u, int f){
	if (f) ans2.push_back(u);
	else ans1.push_back(u);
	dfs[u] = 1;
	for (auto Z : nxt[u]) if (!dfs[Z]) {DFS(Z, f); return;}
}

int main(){
	int cx, cy;
	scanf("%d%d", &n, &m);
	FOE(i, 1, m){
		int s, t; scanf("%d%d", &s, &t);
		nxt[s].push_back(t);
		nxt[t].push_back(s);
		cx = s; cy = t;
	}
	
	dfs[cy] = 1;
	DFS(cx, 0);
	DFS(cy, 1);
	printf("%lu\n", ans1.size() + ans2.size());
	for (int i = ans1.size() - 1; i >= 0; i--) printf("%d ", ans1[i]);
	for (int i = 0; i < ans2.size(); i++) printf("%d%c", ans2[i], (i == ans2.size() - 1?'\n':' '));
}



Measured memory_bytes: 21752
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int K=sc.nextInt();	//縦
		int S=sc.nextInt();	//横
		int num=0;

		for(int i=0;i<=K;i++){
			for(int j=0;j<=K;j++){
				if(S-i-j>=0 && S-i-j<=K) num++;
			}
		}
		System.out.println(num);
	}
} 

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   char s; int cnt=0; 
   rep(i,3){
       cin>>s;
       if(s=='1')cnt++;
   }
   cout<< cnt << endl;
}


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

using namespace std;

typedef long long ll;
constexpr int INF = numeric_limits<int>::max() / 2;

// BIT
// initialize : FenwickTree(n)
// add(pos, n): data[pos] += n;
// sum(l, r)  : sum [l, r)
template <typename T>
class FenwickTree
{
  const int n;
  vector<T> data;

public:
  FenwickTree(int count) : n(count), data(count, 0) { ; }

  void add(int pos, const T &value)
  {
    assert(0 <= pos && pos < n);
    for (int i = pos; i < n; i |= i + 1)
      data[i] += value;
  }

  T sum(int pos) const
  {
    assert(0 <= pos && pos <= n);
    T res = 0;
    for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1)
    {
      res += data[i];
    }
    return res;
  }

  T sum(int l, int r) const
  {
    assert(0 <= l && l <= r && r <= n);
    return sum(r) + (-sum(l));
  }
  using value_type = T;
  using update_type = T;
};

vector<vector<ll>> dp(2010, vector<ll>(2010, INF));
// costb[i][j] := i black, j white -> i+1 black
vector<vector<ll>> costb(2020, vector<ll>(2020, 0)), costw(2020, vector<ll>(2020, 0));

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

  int n;
  cin >> n;
  vector<ll> a(2 * n);
  vector<char> c(2 * n);
  for (int i = 0; i < 2 * n; i++)
  {
    cin >> c[i] >> a[i];
  }

  for (int j = 0; j <= n; j++)
  {
    int wh = 0;
    FenwickTree<int> ft(n + 10);
    for (int i = 0; i < 2 * n; i++)
    {
      if (c[i] == 'W')
      {
        if (a[i] > j)
        {
          wh++;
        }
      }
      else
      {
        int x = a[i];
        costb[x-1][j] = ft.sum(x + 1, n + 1) + wh;
        ft.add(x, 1);
      }
    }
  }

  for (int i = 0; i <= n; i++)
  {
    int bl = 0;
    FenwickTree<int> ft(n + 10);
    for (int j = 0; j < 2 * n; j++)
    {
      if (c[j] == 'B')
      {
        if (a[j] > i)
        {
          bl++;
        }
      }
      else
      {
        int y = a[j];
        costw[i][y-1] = ft.sum(y + 1, n + 1) + bl;
        ft.add(y, 1);
      }
    }
  }

  dp[0][0] = 0;
  for (int i = 0; i <= n; i++)
  {
    for (int j = 0; j <= n; j++)
    {
      if (i == 0 && j == 0)
        continue;
      if (i == 0)
      {
        dp[i][j] = dp[i][j - 1] + costw[i][j - 1];
      }
      else if (j == 0)
      {
        dp[i][j] = dp[i - 1][j] + costb[i - 1][j];
      }
      else
      {
        dp[i][j] = min(dp[i][j - 1] + costw[i][j - 1], dp[i - 1][j] + costb[i - 1][j]);
      }
    }
  }
  cout << dp[n][n] << endl;
}


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

 #define maxn 2000000
 #define INF maxn*10
 #define pb push_back
 #define popb pop_back()
 #define all(x) (x).begin(), (x).end()
 #define rall(x) (x).rbegin(), (x).rend()
 #define f first
 #define s second
 #define forn(i, n) for (int i = 0; i < (int)(n); ++i)
 #define ROF(i, n) for (int i = (int)(n)-1; i <= 0; --i)
 #define see_tree for(int i = 1; i <2*n ; i++)cout << tree[i] << " "
 #define mid (l+r)/2
 #define mod 1000000007

 using namespace std;

    long long n, a, b, c, ar[200];
 int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> c;
    if(n%c!=0)cout << min(abs(n%c-c),n%c);
    else cout << n%c;
 return 0;
 }



Measured memory_bytes: 256