akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main() {
    int64_t N, M;
    cin >> N >> M;
    vector<int64_t> A(N);
    for (int64_t i = 0; i < N; i++) {
        cin >> A[i];
    }

    if (N == 1) {
        cout << A[0] * 2 << endl;
        return 0;
    }

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

    int64_t ok = 0, ng = A[N - 1] + A[N - 2] + 1;
    while (ng - ok != 1) {
        int64_t mid = (ok + ng) / 2;

        //全ての握手をmid以上にできるか？
        int64_t num = 0;
        for (int64_t i = 0; i < N; i++) {
            //A[i]と組にしても良いのは足してmid以上のもの
            num += 2 * (A.end() -  lower_bound(A.begin() + i + 1, A.end(), mid - A[i]));
            if (2 * A[i] >= mid) {
                num++;
            }
        }

        (num >= M ? ok = mid : ng = mid);
    }

    //ok以上にできるので構築
    vector<int64_t> sum(N + 1, 0);
    for (int64_t i = 0; i < N; i++) {
        sum[i + 1] = sum[i] + A[i];
    }
    int64_t ans = 0;
    int64_t num = 0;
    for (int64_t i = 0; i < N; i++) {
        //A[i]と明らかに組にしても良いのは足してokを超えるもの
        int64_t curr_num = A.end() -  upper_bound(A.begin() + i + 1, A.end(), ok - A[i]);
        ans += 2 * (A[i] * curr_num + sum[N] - sum[N - curr_num]);
        num += 2 * curr_num;

        if (2 * A[i] >= ok) {
            ans += 2 * A[i];
            num++;
        }
    }

    //たりないものは全部ok
    ans += ok * (M - num);

    cout << ans << endl;
}

Measured memory_bytes: 1792
INF = float('inf')


def tc():
    n = int(input())
    p = list(map(float, input().split()))

    # dp = [[0] * (n + 1) for _ in range(n + 1)]
    # dp[0][0] = 1
    # # dp[i][j]: probability that out of the first
    # # i coins, j of them are heads
    # for i in range(1, n + 1):
    #     dp[i][0] = dp[i - 1][0] * (1 - p[i - 1])
    #     for j in range(1, i + 1):
    #         dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]

    # ans = sum(dp[n][n // 2 + 1:])
    # print(ans)

    dp = [0] * (n + 1)
    dp[0] = 1
    # dp[i]: probability of i heads so far
    for i, p_heads in enumerate(p):
        for j in reversed(range(1, i + 1 + 1)):
            dp[j] = dp[j - 1] * p_heads + dp[j] * (1 - p_heads)
        dp[0] *= 1 - p_heads

    ans = sum(dp[n // 2 + 1:])
    print(ans)


tc()


Measured memory_bytes: 74092
import java.util.Scanner;

public class Main{
	public static String solve(int[] line){
		String ans = "YES";
		int[] a = new int[10];
		int[] b = new int[10];
		int indexA = 0;
		int indexB = 0;
		a[0] = line[0];
		for(int i = 1; i < line.length; i++){
			if( line[i] > a[indexA] ){
				indexA++;
				a[indexA] = line[i];
			} else if( b[0] == 0 ){
				b[0] = line[i];
			} else if( line[i] > b[indexB] ){
				indexB++;
				b[indexB] = line[i];
			} else {
				ans = "NO";
				break;
			}
		}
		return ans;
	}
				
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String[] result = new String[10000];
		int index = 0;
		
		int n = stdIn.nextInt();
		for(int i = 0; i < n; i++){
			int[] line = new int[10];
			for(int j = 0; j < 10; j++){
				line[j] = stdIn.nextInt();
			}
			result[index] = solve(line);
			index++;
		}
		for(int i = 0; i < index; i++){
			System.out.println(result[i]);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
using namespace std;
char ch[5]={'a','e','i','o','u'};
int main(){
    char c;
    cin >> c;
    for(int i=0;i<5;i++){
        if(c==ch[i]){
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	static ll N;
	static ll A[200010],B[200010];
	scanf("%lld",&N);
	for(int i = 0 ; i < N ; i ++){
		scanf("%lld%lld",&A[i],&B[i]);
	}
	
	ll sum = 0, ret = 10000000000;
	for(int i = 0 ; i < N ; i ++){
		sum += A[i];
		if(A[i] > B[i])ret = min( ret , B[i] );
	}
	if(ret == 10000000000)cout << 0 << endl;
	else cout << sum-ret << endl;
}



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

int main(){
    long long n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    long long minMove = min({a, b, c, d, e}); //ボトルネック
    //long long ans = ((n + minMove) - 1) / minMove + 4;
    long long ans = (n-1)/minMove + 5;
    cout << ans << endl;
}

//最小容量の交通機関に合わせる
//最小容量の人数ずつn人を分ける⇒グループ数はn-1/x + 1
//もし、n/x+1とすると、xがnの約数のときにグループ数が一つ増えてズレる
//グループを0秒から順次出発させる
//最後のグループが出発するのはn/x秒後
//最後のグループは5つの交通機関を使い、1分ずつ計5分でゴール


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
struct YPO
{
    double x;
    double y;
};
struct YPO a[100];
double ci=0;
int b[10];
int b2=0;
int b3[10];
int n;
int cc=0;
int gg=0;
void GG(int a1,int b1)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        if(b[i]==0)
        {
            //printf("%d ",i);
            b[i]=1;
            b3[b2]=i;
            b2++;
            GG(a1-1,i);
            b[i]=0;
            b2--;
        }
    }
    if(a1==0)
    {
        gg++;
        int yy=-1;
        for(i=0;i<n;i++)
        {
            if(yy!=-1){
            int k=b3[i];
            ci=ci+sqrt((a[k].x-a[yy].x)*(a[k].x-a[yy].x)+(a[k].y-a[yy].y)*(a[k].y-a[yy].y));
            }
            yy=b3[i];
        }
        //printf("\n");
    }
}
int main()
{
    int i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lf%lf",&a[i].x,&a[i].y);
    }
    GG(n,-1);
    for(i=1;i<=n;i++)
        ci=ci/i;
    printf("%.10lf\n",ci);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    map<int,int>mm;
    int x;
    int tot=0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        mm[x]++;
        tot^=x;
    }
    int sz=mm.size();
    if(sz>3)
    {
        cout<<"No";
    }
    else
    {
        vector<int>v;
        for(auto i:mm)
            v.push_back(i.second);
        int tt1=(n+2)/3;
        int tt2=(n+1)/3;
        int tt3=n/3;
        sort(v.begin(),v.end());
        if(v.back()>=tt1)
        {
            int z=v.back();
            v.pop_back();
            z-=tt1;
            if(z>0)
                v.push_back(z);
            sort(v.begin(),v.end());

            if(v.back()>=tt2)
            {
                int z=v.back();
                v.pop_back();
                z-=tt2;
                if(z>0)
                    v.push_back(z);
                sort(v.begin(),v.end());                
                if(v.back()>=tt3)
                {
                    if(tot==0)
                        cout<<"Yes";
                    else
                        cout<<"No";
                }
                else
                    cout<<"No";
            }
            else
            {
                cout<<"No";
            }
        }
        else
        {
            cout<<"No";
        }
    }
} 


Measured memory_bytes: 5120
#include<iostream>
using namespace std;
int main(){
    int a,b,n;
    while(cin>>a>>b>>n){
        int ans=0;
        while(n--){
            a=a%b*10;
            ans+=a/b;
            a=a%b;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1160
int main(void){
    int a = 0;
    char op;
    int b = 0;
    int c = 0;
    int f = 0;
   
    while (1){
        scanf("%d %c %d", &a, &op, &b);
   
        if (op == '+'){
            c = a + b;
        }
        else if (op == '-'){
            c = a - b;
        }
        else if (op == '*'){
            c = a*b;
        }
        else if (op == '/'){
            c = a / b;
        }
        else{
            break;
        }
        printf("%d\n", c);
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve(){
    ll a, b;
    cin >> a >> b;
    ll ans = 0, k = 1;
    while(k < b){
        ans ++;
        k += (a-1); //cout << k << " ";
    }
    cout << ans;
}
main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  string s;
  cin>>s;
  if(s=="ani") cout<<"square1001"<<endl;
  else cout<<"e869120"<<endl;

  return 0;
}




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

int main(){
    string s;
    cin >> s;
    int n=s.length();
    string ss=s.substr(0,(n-1)/2);
    string ss1=s.substr(0,(n-1)/2);
    reverse(ss.begin(),ss.end());
    string sss=s.substr(((n+3)/2)-1);
    string sss1=s.substr(((n+3)/2)-1);
    reverse(sss.begin(),sss.end());

    string s1=s;
    reverse(s.begin(),s.end());
    if(ss==ss1 && sss==sss1 && s==s1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <memory.h>
int y[24*3600];
int main(void){
	int n,h,m,s,i,max;
	while(scanf("%d",&n),n){
		max=0;
		memset(y,0,sizeof(y));
		for(i=0;i<2*n;i++){
			scanf("%d:%d:%d",&h,&m,&s);
			if(!(i%2))y[h*3600+m*60+s]++;
			else y[h*3600+m*60+s]--;
		}
		for(i=0;i<24*3600;i++){
			if(i>0)y[i]+=y[i-1];
			if(y[i]>max)max=y[i];
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 1372
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define per(i,x,y) for (int i=(x); i>=(y); i--)
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 1000000000
#define INF 1000000000000000000ll
#define pii pair<int,int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define y1 y1_
#define cmin(x,y) (x)=(y)<(x)?(y):(x)
#define cmax(x,y) (x)=(y)>(x)?(y):(x)
#define mset(x,y) memset((x),(y),sizeof(x))
#define mcpy(x,y) memcpy((x),(y),sizeof(y))
using namespace std;
const ld pi=acos(-1);
const ld eps=1e-8;
//////////////////////// header files ////////////////////////
ll read(){
	char ch=getchar(); ll x=0; int op=1;
	for (; !isdigit(ch); ch=getchar()) if (ch=='-') op=-1;
	for (; isdigit(ch); ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
void write(ll a){
	if (a<0) putchar('-'),a=-a;
	if (a>=10) write(a/10); putchar(a%10+'0');
}
////////////////////////// fast i/o //////////////////////////
#ifdef mod
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x%mod) if (p&1) ret=ret*x%mod;
	return ret;
}
ll get_inv(ll x){
	return ksm(x,mod-2);
}
#else
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x) if (p&1) ret=ret*x;
	return ret;
}
#endif
//////////////////////////// qpow ////////////////////////////
#define N 200005
int n,a[N],b[N];
//#define local
int main(){
#ifdef local
	freopen("test.in","r",stdin); freopen("test.out","w",stdout);
#endif
	n=read(); rep (i,1,n) b[i]=a[i]=read();
	sort(b+1,b+1+n);
	rep (i,1,n){
		if (a[i]<=b[n/2]) printf("%d\n",b[n/2+1]);
		else printf("%d\n",b[n/2]);
	}
	return 0;
}
// sample data:
/*

*/

// rest:
/*

*/

Measured memory_bytes: 3712
N,M,X=map(int,input().split())
ca =[list(map(int,input().split())) for i in range(N)]
ans=float('inf')
for i in range(1,2**N):
    rikaido=[0]*M
    money=0
    for j in range(N):
        if i>>j&1:
            money +=ca[j][0]
            for k in range(1,M+1):
                rikaido[k-1] += ca[j][k]
        for l in range(M):
            if all(rikaido[l] >= X for l in range(M)):
                ans=min(money,ans)
if ans==float('inf'):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll h,w,k;
  cin >> h >> w >> k;
  ll ans=1;
  mat dp(h+1,vec(w));
  dp[0][0]=1;
  for(ll i=0;i<h;i++) {
    for(ll k=0;k<(1<<(w-1));k++) {
      if((k&k/2)) continue;
      for(ll j=0;j<w;j++) {
        if(j!=w-1&&k>>j&1) {
          (dp[i+1][j]+=dp[i][j+1])%=mod;
        }
        else if(j>0&&k>>(j-1)&1) {
          (dp[i+1][j]+=dp[i][j-1])%=mod;
        }
        else {
          (dp[i+1][j]+=dp[i][j])%=mod;
        }
      }
    }
  }
  cout << dp[h][k-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> A(3, 0);
int K;
int main() {
    for(int i = 0; i < 3; ++i) {
        cin >> A.at(i);
    }
    cin >> K;

    sort(A.begin(), A.end(), greater<int>());

    for(int i = 0; i < K; ++i) {
        A.at(0) *= 2;
    }

    int sum = 0;
    for(int i = 0; i < 3; ++i) {
        sum += A.at(i);
    }

    cout << sum << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
#include <queue>

using namespace std;
using edge_set = unordered_set<int>;

int main() {

    int V, E;
    cin >> V >> E;

    int count = 0;
    pair<int, int> order[V];
    edge_set indeg[V], outdeg[V];

    for (int i = 0; i < V; i++) {
        order[i].second = i;
    }

    int s, t;
    for (int i = 0; i < E; i++) {
        int s, t;
        scanf("%d %d", &s, &t);
        indeg[t].insert(s);
        outdeg[s].insert(t);
    }

    queue<int> que;

    for (int i = 0; i < V; i++) {
        if (indeg[i].empty()) {
            que.push(i);
        }
    }

    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (int v : outdeg[u]) {
            indeg[v].erase(u);
            if (indeg[v].empty()) {
                que.push(v);
            }
        }
        cout << u << endl;
    }
}


Measured memory_bytes: 8508
import java.util.Arrays;
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {

            int n = scanner.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int res = 0;
            Arrays.sort(nums);
            for (int i = 0; i < nums.length - 2; i++) {
                for (int j = i + 1; j < nums.length - 1; j++) {
                    if (nums[j] == nums[i]) {
                        continue;
                    }
                    for (int k = j + 1; k < nums.length; k++) {
                        if (nums[k] == nums[j]) {
                            continue;
                        }
                        if (nums[i] + nums[j] > nums[k]) {
                            res++;
                        }
                    }
                }
            }
            System.out.println(res);
        }
    }

}


Measured memory_bytes: 27508
// CODE by Kazhybay Askar
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define iter   set<int>::iterator
#define f      first
#define s      second
#define pb     push_back
#define pf     push_front
#define mp     make_pair
#define cont   continue
#define ll     long long
#define Speed  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define sz     size()
#define all(x) x.begin(),x.end()
#define cont   continue
#define r0     return 0
#define endl   '\n'

const int MAXN = 1e5  + 7;
const int MOD  = 1e9  + 7;
const int INF  = 1e9  + 7;
const ll  MINF = 1e18 + 7;
const int EPS  = 1e-6;
const int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
const int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
const double pi = acos(-1.0);


typedef long double   ld;
typedef pair<ll,ll>   pll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;

ll a[MAXN],b[MAXN];
vector<int>g[MAXN],v;
bool used[MAXN];
ll n,k,cnt=0,sum=0,ans=0,mx=0,mn=INF;
bool y=0;
unordered_map<char,int>m;
void freopen(){
	freopen("A.in","r",stdin);
	freopen("A.out","w",stdout);
}


void solve(){
	string s;
	cin>>s;
	for(int i=0;i<s.sz;i++){
        ans+=cnt-m[s[i]];
        m[s[i]]++;
        cnt++;
	}
	cout<<ans+1;
}

int main(){
	Speed;
	ll T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	r0;
}




Measured memory_bytes: 3152
use std::io::{stdin, stdout, Write};

fn read_line()-> String {
    let mut s = String::new();
    let _ = stdout().flush();
    stdin().read_line(&mut s).expect("Did not enter a correct string");
    if let Some('\n') = s.chars().next_back() {
        s.pop();
    }
    if let Some('\r') = s.chars().next_back() {
        s.pop();
    }
    s
}

fn read_num_line()->Vec<i32> {
    let line = read_line();
    let s_vec = line.split(" ").collect::<Vec<&str>>();
    let mut n_vec = Vec::new();
    for s in s_vec {
        let num: i32 = s.parse().unwrap();
        n_vec.push(num);
    }
    n_vec
}

fn main() {
    let line = read_num_line();
    let a = line[0];
    let b = line[1];
    let c = line[2];
    let result = c-a+b;
    println!("{}", if result < 0 {0}else{result});
}


Measured memory_bytes: 4352
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

ll inv(ll x){
	ll ret = 1, p = MOD;
	while(p){
		if(p&1) ret = ret * x % MOD;
		x = x * x % MOD;
		p >>= 1;
	}
	return ret;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	V a(n);
	SCAN(a);
	
	
	if(n==k){
		ll ans = 1;
		REP(i, 0, n) ans = ans * a[i] % MOD;
		printf("%ld\n", (ans+MOD)%MOD);
		return 0;
	}

	V pl, mi;
	REP(i, 0, n){
		if(a[i]>=0) pl.push_back(a[i]);
		else mi.push_back(a[i]);
	}
	std::sort(ALL(pl));
	std::sort(ALL(mi), std::greater<ll>());

	if(pl.size()==0){
		ll ans = 1;
		if(k%2) REP(i, 0, k) ans = ans * mi[i] % MOD;
		else REP(i, 0, k) ans = ans * mi[n-i-1] % MOD;
		printf("%ld\n", (ans+MOD)%MOD);
		return 0;
	}

	ll ans = 1;
	while(k){
		ll x=pl.size(), y=mi.size();
		if(k>=2){
			ll pl2 = pl[x-2] * pl[x-1], mi2 = -1;
			if(y>=2) mi2 = mi[y-2] * mi[y-1];
			
			if(x>=2 and y<2){
				ans = ans * pl[x-1] % MOD;
				pl.pop_back();
				k -= 1;
				continue;
			}else if(x<2 and y>=2){
				ans *= mi[y-2] * mi[y-1] % MOD;
				ans %= MOD;
				mi.pop_back();
				mi.pop_back();
				k -= 2;
				continue;
			}

			if(pl2>mi2){
				ans = ans * pl[x-1] % MOD;
				pl.pop_back();
				k -= 1;
			}else{
				ans *= mi[y-2] * mi[y-1] % MOD;
				ans %= MOD;
				mi.pop_back();
				mi.pop_back();
				k -= 2;
			}
		}else{
			ans = ans * pl[x-1] % MOD;
			k --;
		}
	}
	printf("%ld\n", (ans+MOD)%MOD);
	return 0;
}



Measured memory_bytes: 6892
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
ll pown(ll fi,ll se){
  ll ans=1;
  rep(i,se){
    ans*=fi;
  }
  return ans;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}

/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/
vector<vector<int>> dir{{1,0},{0,1},{-1,0},{0,-1}};
ll h,w;
void dfs(int x,int y,int cnt,vector<ll> &tmp,vector<vector<ll>> &a){
    bool f=false;
    
    rep(i,4){
      if(x+dir[i][0]>=0&&x+dir[i][0]<h&&y+dir[i][1]>=0&&y+dir[i][1]<w){
        if(a[x+dir[i][0]][y+dir[i][1]]>a[x][y]){
          f=true;
          cnt++;
          dfs(x+dir[i][0],y+dir[i][1],cnt,tmp,a);
          cnt--;
        }
      }
    }
    if(!f){
      tmp.push_back(cnt);
      op(cnt);
      cout<<":"<<endl;
    }
  }

void setup(){
  
  cin>>h>>w;
  ll last=0;
  vec(ans,0);
  mat(a,h,w);
  rep(i,h){
    rep(j,w){
      
      cin>>a[i][j];
    }
  }
  rep(i,h){
    rep(j,w){
      rep(k,4){
        if(i+dir[k][0]>=0&&i+dir[k][0]<h&&j+dir[k][1]>=0&&j+dir[k][1]<w){
          if(a[i+dir[k][0]][j+dir[k][1]]<=a[i][j]){
            break;
          }
        }
        if(k==3){
          op(i);
          op(j);
          dfs(i,j,1,ans,a);
        }
      }
    }
  }
  cout<<endl;
  rep(i,ans.size()){
    last+=(ans[i]-1)*(ans[i])/2;
    last%=MOD;
  }
  op((last+(h*w))%MOD);
}

int main(){
  ll a,b,t;
  cin>>a>>b>>t;
  op((t/a)*b);
  return 0;

}

Measured memory_bytes: 384
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife
	
	int n, k;
	cin >> n >> k;
	vector<int> c(n+1), p(n+1);
	vector<vector<ll>> dp(n+1, vector<ll>(1)), mx = dp;
	for(int i = 1; i <= n; i++)
		cin >> p[i];
	for(int i = 1; i <= n; i++)
		cin >> c[i];
	for(int i = 1; i <= n; i++) {
		int it = i;
		mx[i][0] = -LINF;
		it = p[it];
		while(true) {
			dp[i].push_back(dp[i].back()+c[it]); 
			mx[i].push_back(max(mx[i].back(), dp[i].back()));
			if(it == i)
				break;
			it = p[it];
		}
	}
	//for(int i = 1; i <= n; i++)
		//for(int j = 1; j < dp[i].size(); j++)
			//cout << dp[i][j] << " \n"[j==dp[i].size()-1];
	ll ans = -LINF;
	for(int i = 1; i <= n; i++) {
		int x = dp[i].size()-1;
		int w = k/x, res = k%x;
		ll cur = -LINF;
		if(dp[i][x] > 0) {
			cur = dp[i][x]*w+max<ll>(0, mx[i][res]);
		}
		if(w) {
			cur = max(cur, dp[i][x]*(w-1) + mx[i][x]);
		}
		cur = max(cur, mx[i][min(x, k)]);
		ans = max(ans, cur);
	}
	cout << ans << '\n';

	return 0;
}


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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

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

int n, k;
vector<int> h;
int dp[100005];

int funB(int x)
{

    rep(i, 100005)
    {
        dp[i] = INF;
    }
    dp[0] = 0;

    rep(i, n)
    {
        for (int j = 1; j <= k; j++)
        {
            if (i + j >= n)
                break;
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    return dp[n - 1];
}

signed main()
{
    cin >> n >> k;
    h.resize(n);
    rep(i, n)
    {
        cin >> h[i];
    }

    int ans = funB(n);

    print(ans);
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))

x=0
y=0
a.sort()
i=n-1
while (i>0):
  if a[i-1]==a[i]:
    x=y
    y=a[i]
    if x>0:
      break
    i-=2
  else:
    i-=1

print(x*y)

Measured memory_bytes: 14244
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

int main(){
    ll a;
    cin >> a;
    ll b;
    cin >> b;
    ll n;
    cin >> n;
    if(n>=b){
        cout<<((b-1)*a-(b-1)*a%b)/b<<endl;
    }else{
        cout<<(n*a-n*a%b)/b<<endl;
    }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;
int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ulli n, AC=0, WA=0, TLE=0, RE=0;
  cin>>n;
  string aux;
  for(ulli i=0; i<=n; ++i)
  {
    getline(cin, aux);
    if(aux=="AC")
    AC++;
    if(aux=="WA")
    WA++;
    if(aux=="TLE")
    TLE++;
    if(aux=="RE")
    RE++;
  }
  cout<<"AC x "<<AC<<ENDL;
  cout<<"WA x "<<WA<<ENDL;
  cout<<"TLE x "<<TLE<<ENDL;
  cout<<"RE x "<<RE<<ENDL;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;

struct QST{
	int i,b;
};
bool operator < (const QST &a,const QST &b) {return a.b<b.b;}

int n,a[maxn],b[maxn];
priority_queue<QST> Q;

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n) scanf("%d",&b[i]);
	
	fo(i,1,n) Q.push((QST){i,b[i]});
	LL ans=0;
	while (!Q.empty())
	{
		QST tp=Q.top(); Q.pop();
		int i=tp.i;
		if (b[i]>a[i] && b[i]>=b[i%n+1]+b[(i==1)?n:i-1])
		{
			int sum=b[i%n+1]+b[(i==1)?n:i-1];
			if (a[i]>=b[i]%sum && (b[i]-a[i])%sum!=0) {ans=-1; break;}
			int d=min(b[i]-a[i],b[i]-b[i]%sum);
			b[i]-=d;
			ans+=d/sum;
			Q.push((QST){i,b[i]});
		}
	}
	fo(i,1,n) if (a[i]!=b[i]) {ans=-1; break;}
	
	printf("%lld\n",ans);
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL vector<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
void Y()
{
    cout<<"Yes"<<endl;
}
void N()
{
    cout<<"No"<<endl;
}
V<LL>v;
map<LL,LL>u;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    string a;
    cin>>n;
    l=0;
    for(i=0; i<n; i++)
    {
        cin>>o;
        l=max(l,o);
        v.PSB(o);
    }
    j=0;
    k=0;

    for(j=0,i=1,s=0; j<v.SZ; j++)
    {
        if(v[j]==i)
        {
            k++;
            i++;
        }
    }
    if(k==0)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<n-k<<endl;
    }

    return 0;
}


Measured memory_bytes: 2548
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	bool same = true;
	string c[2];
	cin >> c[0];
	cin >> c[1];
	if (c[0][0] != c[1][2]) same = false;
	if (c[0][1] != c[1][1]) same = false;
	if (c[0][2] != c[1][0]) same = false;

	cout << (same ? "YES" : "NO") << endl;
	return 0;
}

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

using namespace std;

#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define dump(x) cerr << "~ " << #x << " = " << x << endl


int main() {

	fast_cin;
	
	int ar[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

	int n;
	cin >> n;

	cout << ar[n-1] << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
N,X,M = map(int,input().split())
A = X%M
Ans = A
Modset = set()
Modset.add(A)
i = 1
for _ in range(10**6):
    A = pow(A,2,M)
    if A not in Modset:
        Modset.add(A)
        Ans += A
        i += 1
    else:
        break
if 0 in Modset:
    print(Ans)
else:
    S = A
    B = A
    j = 1
    for _ in range(10**6):
        B = pow(B,2,M)
        if A != B:
            S += B
            j += 1
        else:
            break
    rep = (N-i)//j
    Ans += S*rep
    i += j*rep
    if i < N:
        i += 1
        Ans += A
        for _ in range(10**10):
            if i == N:
                break
            else:
                i += 1
                A = pow(A,2,M)
                Ans += A
    print(Ans)

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

int a, b;

void f(int x) {
    a = x % 10;
    b = 0;
    while (x) {
        b = x;
        x /= 10;
    }
}

signed main() {
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  string str; cin >> str;
  int left = 0, right = 0;
  for(int i=0;i<N;i++){
    if(str[i] == '(') left++;
    else{
      // str[i] == ')'
      if(left >= 1){
        left--;
      }else{
        right++;
      }
    }
  }
  // cout << left << " " << right << endl;
  for(int i=0;i<right;i++) cout << '(';
  cout << str;
  for(int i=0;i<left;i++) cout << ')';
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scanner=new Scanner(System.in);

		int n=scanner.nextInt();


		Integer[] data=new Integer[n];

		for(int i=0;i<n;i++) {
			data[i]=scanner.nextInt();
		}

		Arrays.sort(data,Comparator.reverseOrder());

		int result=data[0]-data[n-1];

		System.out.println(result);



		scanner.close();

	}

	public static int getsumofkakuketa(int n) {

		int result=0;

		while(true) {

			result+=n%10;

			if(n/10!=0) {
				n/=10;
			}else {
				return result;
			}
		}



	}

	public static boolean isMacthed(int a,int b,int sum) {

		if(sum>=a && sum<=b) {
			return true;
		}else {
			return false;
		}

	}



}







Measured memory_bytes: 23892
#include<stdio.h>
#include<string.h>
int main()
{
    int l,i,flag=1;
    char s[11],t[11];
    scanf("%s",s);
    scanf("%s",t);
    l=strlen(s);
    for(i=0;i<l;i++)
    {
        if(s[i]!=t[i])
        {
            flag=0;
            break;
        }
    }
    if(flag==0)
    {
        printf("No");
    }
    else
    {
        printf("Yes");
    }
}


Measured memory_bytes: 1704
#include<iostream>
#include<algorithm>
using namespace std;
#define INF (1<<20)
int dp[10001] = { 0 };
int itemsw[1000], itemsv[1000];

int main()
{
	int N, W; cin >> N >> W;
	for (int i = 0; i < N; ++i) {
		cin >> itemsv[i]>>itemsw[i];
	}
	for (int i = 0; i < N; ++i)	for (int j = 0; j <= W; ++j) {
			if (j >= itemsw[i])
				dp[j] = max(dp[j], dp[j - itemsw[i]] + itemsv[i]);
	}
	cout << dp[W] << endl;
}

Measured memory_bytes: 1208
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; i++) a[i] = sc.nextInt();
        for(int i = 0; i < n; i++) b[i] = sc.nextInt();
        int[] suma = new int[n];
        int[] sumb = new int[n];
        suma[0] = a[0];
        sumb[n-1] = b[n-1];
        for(int i = 1; i < n; i++){
            suma[i] = suma[i-1] + a[i];
            sumb[n - i - 1] = sumb[n - i] + b[n - i - 1];
        }
        int ans = 0;
        for(int i = 0; i < n; i++)
            ans = Math.max(ans, suma[i] + sumb[i]);
        System.out.println(ans);
    }
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += a[i] * a[j];
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

int dpw(int a){
  int b=1;
  while(a){
    b*=2; a--;
  }
  return b;
}

int main(){
  int L; cin>>L;
  vector<int> V(19,0);
  int mx;
  for(int i=0;1;i++){
    V[i]=L%2;
    L/=2;
    if(L==0){
      mx=i;
      break;
    }
  }
  vector<vector<int>> ANS;
  for(int i=0;i<mx;i++){
    ANS.push_back({i+1,i+2,0});
    ANS.push_back({i+1,i+2,dpw(i)});
  }
  int a=0;
  for(int i=mx;i>=0;i--){
    if(V[i]){
      if(i!=mx)
        ANS.push_back({i+1,mx+1,a});
      a+=dpw(i);
    }
  }
  a=ANS.size();
  cout<<mx+1<<" "<<a<<endl;
  for(int i=0;i<a;i++)
    cout<<ANS[i][0]<<" "<<ANS[i][1]<<" "<<ANS[i][2]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	char s[10010];
	scanf("%s",&s);
	bool flag = true;
	int cc = 0;
	for(int i = 0;i < strlen(s);i++){
		if(s[i] == 'C')cc++;
		if(s[i] != 'A' && s[i] != 'C' && isupper(s[i]))flag = false;
	}
	if(cc != 1 || s[0] == 'C' || s[1] == 'C' || s[strlen(s) - 1] == 'C')flag = false;
	if(s[0] != 'A')flag = false;
	if(flag)printf("AC\n");
	else printf("WA\n");
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter syso = new PrintWriter(System.out);
		int n=sc.nextInt();
		int arr[]=sc.nextArr(n);
		long ans=0;
		for(int i=0;i<n-1;i++) {
			int a=arr[i]-arr[i+1];
			if(a>0) {
				ans+=a;
				arr[i+1]+=a;
			}
		}
		syso.println(ans);
        syso.close();
    }
    
 
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
		public int[] nextArr(int n) throws IOException{
			int arr[]=new int[n];
			for(int i=0;i<n;i++)arr[i]=nextInt();
			return arr;
		}
		public BigInteger BigInteger(String s) throws IOException{
			BigInteger a=new BigInteger(s);
			return a;
		}
 
	}
}

Measured memory_bytes: 53924
#include<bits/stdc++.h>
using namespace std;
int main()
{   string s;  
    cin>>s;
    int len=s.length();
    if(s[0]==s[len-1])
        if(len%2==1)printf("Second\n");
      else printf("First\n");
    else
        if(len%2==1)printf("First\n");
       else printf("Second\n");
}

Measured memory_bytes: 512
#include <cmath>
#include <vector>
#include <stdio.h>
#include <iostream>
using namespace std;

//-----------------------------------------
string output_text(int D){

    string str;
    if(D==25){       str = "Christmas"; 
    }else if(D==24){ str = "Christmas Eve";
    }else if(D==23){ str = "Christmas Eve Eve";
    }else if(D==22){ str = "Christmas Eve Eve Eve";
    };

    return str;
}

int main() {
    // I/O format
    int D; cin >> D;
    string out;

    out = output_text(D);
    cout << out << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [None]*m
c = [0]*m
for i in range(m):
    a[i], b = map(int, input().split())
    ls = list(map(int,input().split()))
    for j in ls:
        c[i] |= 1<<(j-1)
n2 = 1<<n
dp = [1e9]*(n2)
dp[0] = 0
for i in range(m):
    for S in range(n2):
        if dp[S|c[i]] > dp[S]+a[i]:
            dp[S|c[i]] = dp[S]+a[i]
if dp[(n2)-1] < 1e9:
    print(dp[(n2)-1])
else:
    print(-1)

Measured memory_bytes: 3188
#include<cstdio>
#include<cmath>
#include<bitset>
#include<set>
using namespace std;

typedef long long ll;

const int MAXN = 100010;

ll s[MAXN], r[MAXN], ant[MAXN];
int srt, crt;
bitset<3000> vis;
int prime[3000], tot;
multiset<ll> mset;

inline int Max(int a, int b){return a > b ? a : b;}

ll get(ll a){
	ll b = ll(sqrt(a) + 0.5);
	return b * b == a ? b : -1;
}

void init(int maxn){
	for (int i = 2; i <= maxn; ++i){
		if (!vis[i])
			prime[++tot] = i;
		for (int j = 1; j <= tot && i * prime[j] <= maxn; ++j){
			vis[i * prime[j]] = 1;
			if (i % prime[j] == 0) break;
		}
	}
}

int main(){
	int N; ll maxs = 1;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i){
		scanf("%lld", &s[i]);
		r[i] = s[i], ant[i] = 1;
		if (s[i] > maxs) maxs = s[i];
	}
	srt = int(sqrt(maxs) + 1);
	crt = int(pow(maxs, 1.0 / 3.0) + 1);
	init(crt);
	for (int i = 1; i <= tot; ++i){
		ll tmp = 1ll * prime[i] * prime[i] * prime[i];
		for (int j = 1, cnt; j <= N; ++j){
			cnt = 0;
			while (s[j] % tmp == 0)
				s[j] /= tmp;
			while (r[j] % prime[i] == 0)
				r[j] /= prime[i], ++cnt;
			cnt %= 3;
			if (cnt == 1) ant[j] *= prime[i] * prime[i];
			else if (cnt == 2) ant[j] *= prime[i];
		}
	}
	int ans = 0;
	for (int i = 1, flag = 0; i <= N; ++i){
		ll tmp = get(r[i]);
		if (s[i] == 1){
			if (!flag) flag = 1, ++ans;
		}
		else if (tmp != -1){
			mset.insert(s[i]);
			ant[i] *= tmp;
		}
		else if (r[i] <= srt){
			mset.insert(s[i]);
			ant[i] *= r[i] * r[i];
		}
		else 
			++ans;
	}
	for (int i = 1, c1, c2; i <= N; ++i){
		if (s[i] != 1 && mset.find(s[i]) != mset.end()){
			c1 = mset.erase(s[i]), c2 = mset.erase(ant[i]);
			ans += Max(c1, c2);
		} 
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 7296
#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 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

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

const int inf=100000000;



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

    for(llong i=1;i<=3500; i++)
    {
        for(llong j=1; j<=3500; j++)
        {
           llong a=i+j;
           llong v=N*i*j;
           llong x=4*i*j-N*a;

           if(x>0)
           {
               if(v%x==0)
               {
                   llong w=v/x;
                   cout<<i<<" "<<j<<" "<<w<<endl;
                   return 0;
               }
           }

        }
    }

}

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

// {
#define debug(var)  do{ std::cout << #var << " : "; view(var); }while(0)
using ll = long long;
using ld = long double;
inline int num (const std::string& S, int idx) noexcept { return S.at(idx) - '0'; }
inline int ctoi(char c) noexcept { return c - '0'; }
inline bool isNumber(char c) noexcept { return ('0'<c && c<'9'? true : false); }
inline int safeCtoi(char c) { if(isNumber(c)) { return ctoi(c); } else { throw 1; } }
inline char itoc(int i) noexcept { return i + '0'; }
inline unsigned int bitMask(int i) noexcept { return (1 << i); }
inline bool isTrue(unsigned int bit, int i) noexcept { return bit & bitMask(i); }
inline bool isEven(int num) noexcept { return !num%2; }
inline bool isOdd(int num) noexcept { return num%2; }
template<typename T> inline short sgn(T num) noexcept { return (num==0? 0 : (num>0? 1 : -1) ); }
template<typename T> inline bool isZero(T num) noexcept { return (num==0? true : false); }
template<typename T> inline bool isPositive(T num) noexcept { return (num>0? true : false); }
template<typename T> inline bool isNegative(T num) noexcept { return (num<0? true : false); }
template<typename T> void view(T e) noexcept { cout << e; }
template<typename T> void view(std::vector<T> v) noexcept { for(const auto& e : v) cout << e << " "; }
template<typename T> void view(std::vector<std::vector<T>> vv) noexcept { for(const auto& v : vv) view(v); }
//}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	long double a, b, h, m;
	cin >> a >> b >> h >> m;
	long double a_theta = m/60.0 * 2*M_PI;
	long double b_theta = h/12.0 * 2*M_PI + a_theta/12.0;
	long double theta = abs(a_theta - b_theta);
	cout << fixed << setprecision(20) << sqrt( a*a + b*b - 2*a*b*cos(theta) ) << endl;
	return 0;
}

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

int main()
{
       int x, y, z, t;

       scanf("%d %d %d", &x, &y, &z);

       t = x;
       x = z;
       z = y;
       y = t;
       printf("%d %d %d\n", x, y, z);



       return 0;
}

Measured memory_bytes: 128
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int N,M,A,B,C,T;
V mul(const V &a, const V &b){
	V c(N*N);
	int i=0,j;
	for(;i<N;i++)for(j=0;j<N;j++)c[i*N+j]=(a[slice(i*N,N,1)]*b[slice(j,N,N)]).sum()%M;
	return c;
}
V exp(const V &a, const int n){
	if(n==1)return a;
	if(n&1)return mul(exp(a,n-1),a);
	V b=exp(a,n>>1);
	return mul(b,b);
}
V z(){
	V x(N*N);
	int i;
	if(T){
		for(i=0;i<N;i++){
			if(i>0)x[i*N+i-1]=A;
			x[i*N+i]=B;
			if(i<N-1)x[i*N+i+1]=C;
		}
		return exp(x,T);
	}else{
		for(i=0;i<N;i++)x[i*N+i]=1;
		return x;
	}
}
main(){
	int i;
	V s;
	for(;scanf("%d%d%d%d%d%d",&N,&M,&A,&B,&C,&T),N;){
		s.resize(N);
		for(i=0;i<N;i++)scanf("%d",&s[i]);
		const V r=z();
		for(i=0;i<N;i++)printf(i<N-1?"%d ":"%d\n",(r[slice(i*N,N,1)]*s).sum()%M);
	}
}

Measured memory_bytes: 1080