akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 1000000007 
#define N 500005
#define M 1000003
#define LOG 19
#define KOK 250
#define EPS 0.0000001
using namespace std;

int n;
int go[LOG][N],nxt[N][30];
char s[N];

void solve(int l,int r) {

	for(int i=LOG-1;i>=0;i--) {

		if(go[i][l]<=r+1) l=go[i][l];

	}

	if(l==r+1) printf("Yes\n");
	else printf("No\n");

}

void pre_cal() {

	for(int i=0;i<27;i++) nxt[n+1][i]=nxt[n+2][i]=n+2;

	for(int i=n;i>=1;i--) {

		int cc=s[i]-'a';

		nxt[i][cc]=i+1;

		for(int c=cc+1;c<27;c++) nxt[i][c]=nxt[nxt[i][c-1]][c-1];
		for(int c=cc-1;c>=0;c--) nxt[i][c]=nxt[nxt[i][26]][c];

	}
	
	for(int i=1;i<=n+2;i++) go[0][i]=nxt[i][26];

	for(int j=1;j<LOG;j++) {

		for(int i=1;i<=n+2;i++) go[j][i]=go[j-1][go[j-1][i]];

	}

}

int main() {

	scanf("%s",s+1);

	n=strlen(s+1);

	pre_cal();

	int q;

	scanf("%d",&q);

	while(q--) {

		int l,r;

		scanf("%d %d",&l,&r);

		solve(l,r);

	}

}

Measured memory_bytes: 96768
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#define INF 2e9
#define rep(i,m) for(int i=0;i<m;i++)
#define repn(i,n,m) for(int i=n;i<m;i++)


using namespace std;

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

	int ans;
	ans = (c - a) * 60 + d - b - x;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
      static List<string> a = new List<string>();
    static decimal result;
static StringBuilder sb = new StringBuilder();
static decimal N,M,K;
    static void Main()
    {
Read1();
    //(m+1)x=N
//m>0
      //Nの約数で見ていく
      for(int x=1;(double)x<Math.Sqrt((double)N);x++){
      if(N%x==0 && x*(x+1)<N){
       result+=N/x-1;    
      }
      }
                   Console.WriteLine(result.ToString());

    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = decimal.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {
for(int i=0;i<N;i++){
a.Add(Console.ReadLine());
}
 
    }


}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int n,x[20][20],y[20][20],m[20],z=1,ans;
int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>m[i];
		for (int j=0;j<m[i];j++) cin>>x[i][j]>>y[i][j];
	}
	for (int i=0;i<n;i++) z*=2;
	for (int i=0;i<z;i++){
		int a=i,ff=0,num=0;
		bool f[20]={0};
		vector<int> v;v.clear();
		while (a>0){
			v.push_back(a%2);
			a/=2;
		}
		while (v.size()<n) v.push_back(0);
		for (int j=0;j<v.size();j++) f[j]=v[j];
		for (int j=0;j<v.size();j++)
			if (v[j]==1){
				num++;
				for (int k=0;k<m[j];k++) if (f[x[j][k]-1]!=y[j][k]) ff=1;
			}
		if (ff==0) ans=max(ans,num);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<int> g[200010];
map<int,ll> c;
vector<ll> ans;
void dfs(int v, ll x, int pre = -1){
  ans[v] = x + c[v];
  for(int nv : g[v]){
    if(nv==pre)continue;
    dfs(nv, ans[v], v);
  }
}
int main() {
  int n,q;
  cin >> n >> q;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  rep(i,q){
    int p,x;
    cin >> p >> x;
    --p;
    c[p] += x;
  }
  ans = vector<ll>(n);
  dfs(0,0);
  rep(i,n){
    printf("%lld ",ans[i]);
  }
  cout << endl;
}

Measured memory_bytes: 39936
#include <iostream>

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

	int ans = 0;

	int cons = 1, prev = -1;
	std::cin >> prev;
	for (int i = 1; i < n; ++i) {
		int a;
		std::cin >> a;

		if (a == prev)
			++cons;
		else {
			ans += cons / 2;
			cons = 1;
		}

		prev = a;
	}
	if (cons != 1)
		ans += cons / 2;

	std::cout << ans << std::endl;
}

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

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;

		static void Main(string[] args)
		{
			var ab = RIs;
			var a = ab[0];
			var b = ab[1];
			if (a + b == 15) Out("+");
			else if (a * b == 15) Out("*");
			else Out("x");
		}
	}
}


Measured memory_bytes: 13396
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/random.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;
namespace rnd = boost::random;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> D;

  invec<int> c(26);
  vector<vector<int>> s(D, vector<int>(26));
  for (auto&& i : s)
    for (auto&& j : i)
      cin >> j;
  vector<int> t(D), highest;
  ll high = -9999999999, cost = 0;
  rnd::mt19937 mt;
  rnd::uniform_int_distribution rnd_plan(1, 26);
  rnd::uniform_real_distribution<> dist2(0.0, 1.0);

  REP(i, 26) {
    cost += c[i];
  }

  const int tier = cost;
  
  int lastf[26] = {0};
  REP(i, D) {
    pair<int, int> cand = {-999999999, 0};
    
    REP(j, 26)
      cand = max(cand, make_pair(s[i][j] + c[j] * (i + 1 - lastf[j]), j));
    t[i] = cand.second + 1;
    
    const int plan = t[i] - 1;
    lastf[plan] = i + 1;
  }  
  
  const int ITER = 977721600 / D;
  long double temp = 0.5;
  constexpr long double ALPHA = 0.1;
  const long double temp_down = temp * pow(ALPHA, 1.0 / (double)ITER);
  
  REP(loop, ITER) {
    int r = 0;
    int last[26] = {0};
    
    const int update = loop % D;
    const int told = t[update];
    t[update] = (loop != 0) ? rnd_plan(mt) : t[update];
    
    REP(i, D) {
      const int plan = t[i] - 1;
      r += s[i][plan];
      cost -= c[plan] * (i + 1 - last[plan]);
      last[plan] = i + 1;
      r -= cost;
      cost += tier;
    }
    
    if (r > high) {
      high = r;
      highest = t;
    }
    else if (dist2(mt) > exp((double)(r - high) / 128.0 / temp))
      t[update] = told;
    cost = tier;
    temp *= temp_down;
  }
  
  for (auto i : highest)
    cout << i << endl;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}





Measured memory_bytes: 3812
s = input()
check = True
for i in range(len(s)):
    if s[i] != s[-1 - i]:
        check = False
s = s[:len(s)//2]
for i in range(len(s)):
    if s[i] != s[-1 - i]:
        check = False
print("Yes" if check else "No")

Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	
	int sum = a+b+c;
	if(sum>=22) {
		cout << "	bust";
	}	 else {
		cout <<"win";
	}
	return 0;
}

Measured memory_bytes: 256
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,S = map(int,S().split())
A = [0] + LI()
mod = 998244353

dp = [[0]*(S+1) for _ in range(N+1)]

# dp[i][j] = {A_1,…,A_i}の部分集合の部分集合で、和がjとなるものの個数

for i in range(N+1):
    for j in range(S+1):
        if i == 0:
            dp[i][0] = 1
        else:
            if j >= A[i]:
                dp[i][j] = (dp[i-1][j]*2 + dp[i-1][j-A[i]]) % mod
            else:
                dp[i][j] = dp[i-1][j]*2 % mod

print(dp[N][S])

Measured memory_bytes: 132368
#include <stdio.h>
#include <stdlib.h>


#define	ll_int	long long int


typedef struct{
	int front;
	int rear;
} QUEUE_T;


ll_int **QUEUE, *S_QUEUE;
QUEUE_T *QP;	// キューのフロント、リアを管理する配列


// キューの初期化
void  Init(int n)
{
	int i;

	for(i = 0; i < n; i++)
		QP[i].front = QP[i].rear = 0;
}


void Enqueue(int t, int x, int size)
{
	QUEUE[t][(QP[t].rear++) % size] = x;
}


void Front(int t, int size)
{
	if(QP[t].front != QP[t].rear)
		printf("%lld\n", QUEUE[t][(QP[t].front) % size]);
}


void Dequeue(int t, int size)
{
	if(QP[t].front != QP[t].rear)
		QP[t].front++;
}


int main()
{
	int n, q;
	int size;
	int query, t;
	ll_int x;
	int i;

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

	if(q > n)
		size = q;
	else
		size = n;

	S_QUEUE = (ll_int *)malloc(sizeof(ll_int) * n * size);
	QUEUE = (ll_int **)malloc(sizeof(ll_int *) * n);
	for(i = 0; i < n; i++)
		QUEUE[i] = S_QUEUE + (i * size);
	QP = (QUEUE_T *)malloc(sizeof(QUEUE_T) * n);

	Init(n);

	for(i = 0; i < q; i++){
		scanf("%d", &query);

		if(query == 0){
			scanf("%d %lld", &t, &x);
			Enqueue(t, x, size);
		}else if(query == 1){
			scanf("%d", &t);
			Front(t, size);
		}else if(query == 2){
			scanf("%d", &t);
			Dequeue(t, size);
		}
	}

	return 0;
}

/*
	enqueue(t, x): Qtに整数xを挿入する。
	front(t): Qtから次に取り出される要素を報告する。ただし、Qtが空の場合は何もしない。
	dequeue(t): Qtから要素を取り出し削除する。ただし、Qtが空の場合は何もしない。

*/


Measured memory_bytes: 6252
#include<stdio.h>
#include<string.h>
int main(void)
{
  char s[105];
  int i,j=0,k;
  scanf("%s",s);
  k = strlen(s);
  for(i=0;i<k/2;i++)
  {
   if(s[i] != s[k-1-i])
     j++;
  }
  printf("%d\n",j); 
 return 0; 
}

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

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

struct UnionFind {
    vector<int> size, parents;
    UnionFind() {}
    UnionFind(int n) {  // make n trees.
        size.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeTree(i);
        }
    }
    void makeTree(int x) {
        parents[x] = x;  // the parent of x is x
        size[x] = 1;
    }
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
    bool isRoot(int x) { return x == findRoot(x); }
    bool unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) return false;
        if (size[x] > size[y]) {
            parents[y] = x;
            size[x] += size[y];
        } else {
            parents[x] = y;
            size[y] += size[x];
        }
        return true;
    }
    int findRoot(int x) {
        if (x != parents[x]) {
            parents[x] = findRoot(parents[x]);
        }
        return parents[x];
    }
    int treeSize(int x) { return size[findRoot(x)]; }
};

int main() {
  int n,m,x,y,z;
  cin >> n >> m;
  UnionFind U(n);
  for(int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    U.unite(x-1,y-1);
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if (U.isRoot(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4032
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N  = scan.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
        }
        long[] digits = new long[61];
        for (int i = 0; i < N; i++) {
            int point = 0;
            long current = 1;
            while(0 < A[i]) {
                if (0 < (A[i] & current)) {
                    digits[point] += 1;
                }
                A[i] /= 2;
                point += 1;
            }
        }
        long answer = 0;
        long current = 1;
        long mod = 1000000007;
        for (int i = 0; i < 61; i++) {
            long x = digits[i] * (N-digits[i]);
            x %= mod;
            long y = current;
            y %= mod;
            long z = x * y;
            z %= mod;
            answer += z;
            answer %= mod;
            current *= 2;
        }
        System.out.println(answer);
    }
}


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

int main(){
    int n;
    long long sum=0,ans=2e18;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    long long tmp=0;
    for(int i=0;i<n-1;i++){
        tmp+=2*a[i];
        if(i+1<n)ans=min(ans,abs(sum-tmp));
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(void)
{
    int n, m;
    cin >> n >> m;

    vector<pair<long, long>> dr(n);
    for (int i = 0; i < n;i++){
        long a, b;
        cin >> a >> b;
        dr.at(i) = make_pair(a, b);
    }
    sort(dr.begin(), dr.end());
    long cnt = 0;
    for (int i = 0; i < n;i++){
        long a = dr.at(i).first;
        long b = dr.at(i).second;
        for (int j = 1; j <= b; j++)
        {
            if (m <= 0)
                break;
            cnt += a;
            
            m--;
        }
    }
    cout << cnt << endl;
}

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

int main () {
  int N,X,H;
  cin >> X;
  H = 0, N = X;
  while (0<N) H += N%10,N /= 10;
  if ( X%H == 0) cout << "Yes" <<endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main()
{
    ///{}
    ios_base::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
    int n;
    cin>>n;
    vector<int>v(n);
    int mni=0;
    int mxi=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        if(v[i]>v[mxi])
            mxi=i;
        if(v[i]<v[mni])
            mni=i;
    }
    int m=0;
    vector<pair<int,int> >vout;
    if(abs(v[mni])>abs(v[mxi])){
        for(int i=0;i<n;i++){
            if(i==mni)
                continue;
            v[i]+=v[mni];
            vout.push_back({mni,i});
        }
        for(int i=n-1;i>0;i--){
            if(v[i]<v[i-1]){
                v[i-1]+=v[i];
                vout.push_back({i,i-1});
            }
        }
    }else{
        for(int i=0;i<n;i++){
            if(i==mxi)
                continue;
            v[i]+=v[mxi];
            vout.push_back({mxi,i});
        }
        for(int i=0;i<n-1;i++){
            if(v[i]>v[i+1]){
                v[i+1]+=v[i];
                vout.push_back({i,i+1});
            }
        }
    }
    cout<<vout.size()<<'\n';
    for(int i=0;i<vout.size();i++){
    cout<<vout[i].first+1<<' '<<vout[i].second+1<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3672
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
      	int n = Integer.parseInt(line);
      
      	int x = n % 1000;
      	int answer = 0;
      	if(x > 0){
          answer = 1000 - x;
        }
      System.out.println(String.valueOf(answer));
    }
}

Measured memory_bytes: 35608
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;

int main() {
   int val1;
   double ave = 0;
   double sum = 0;
   double sum1 = 0;
   double variance = 0;
   vector<int> nums;
   
   for (int n; cin>>n;) {
        if (n == 0) break;
       for (int i=0; i<n; ++i) {
            cin >> val1;
            nums.push_back(val1);
            sum += val1;
       }
        ave = 1.0*sum / nums.size();
        
        for (int i=0; i<nums.size(); ++i) {
           sum1 += pow(nums[i]-ave, 2);
        }
        
        variance = sqrt(sum1/nums.size());
        printf("%lf\n", variance);
        nums.clear();
        sum = 0;
        ave = 0;
        sum1 = 0;
        variance = 0;
    }
    return 0;
}



Measured memory_bytes: 3276
#include <iostream>
using namespace std;
int main(){
    int n; cin >> n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S = "";
    cin >> S;
    //文字列を反転させる
    reverse(S.begin(), S.end());

    //要素を反転させる
    vector<string> D = {"dream", "dreamer", "erase", "eraser"};
    for (int i = 0; i < 4; ++i) {
        reverse(D.at(i).begin(), D.at(i).end());
    }

    string T = "";
    bool can = true;
    for (int i = 0; i < S.size();) {
        bool can2 = false;
        for (int j = 0; j < 4; ++j) {
            string d = D.at(j);
            if(S.substr(i,d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if (can2 == false){
            can = false;
            break;
        }
    }

    if (can == true){
        cout << "YES";
    } else{
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#include <unistd.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int ops[25000];
int cnt_ops =0;

void move(int cur, vector<int> &P, vector<int> &par) {
	assert(cnt_ops < 20000);
	ops[cnt_ops++] =cur;
	int v =cur, tmp =P[0];
	while(true) {
		swap(P[v], tmp);
		if(v == 0) break;
		v =par[v];
	}
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> P(N), par(N, 0), D(N, 0);
	vector< vector<int> > G(N);
	for(int i =1; i < N; i++) {
		cin >> par[i];
		G[par[i]].push_back(i);
		D[par[i]]++;
	}
	for(int i =0; i < N; i++) cin >> P[i];

	vector<bool> bl(N, false);
	while(!bl[0]) {
		vector<int> in_path(N, -1), in_path_id(N, -1);
		vector< vector< pair<int, int> > > paths;
		for(int i =N-1; i >= 0; i--) if(!bl[i] && D[i] == 0) {
			vector< pair<int, int> > path;
			int v =i;
			while(D[v] <= 1) {
				in_path[v] =paths.size();
				path.push_back(make_pair(v, -1));
				if(v == 0) break;
				v =par[v];
			}
			reverse(begin(path), end(path));
			for(int j =0; j < (int)path.size(); j++) in_path_id[path[j].ff] =j;
			paths.push_back(path);
		}

		int cur =N-1;
		while(true) {
//			for(int i =0; i < N; i++) cerr << P[i] << " "; cerr << "\n";
			int v =P[0];
			if(in_path[v] != -1) {
				int p =in_path[v], x =(int)paths[in_path[v]].size()-1;
				while(paths[p][x].ss > v) x--;
				for(int i =1; i <= x; i++) paths[p][i-1].ss =paths[p][i].ss;
				paths[p][x].ss =v;
				move(paths[p][x].ff, P, par);
			}
			while(cur >= 0) {
				if(bl[cur]) cur--;
				else if(in_path[cur] != -1 && paths[in_path[cur]][in_path_id[cur]].ss != -1) cur--;
				else break;
			}
			if(cur < 0) break;
			if(in_path[v] == -1) {
				move(cur, P, par);
				cur--;
			}
		}
//		for(int i =0; i < N; i++) cerr << P[i] << " "; cerr << ".\n";

		for(int i =0; i < N; i++) if(in_path[i] != -1) {
			bl[i] =true;
			D[par[i]]--;
		}
	}

	cout << cnt_ops << "\n";
	for(int i =0; i < cnt_ops; i++) cout << ops[i] << "\n";
	return 0;}

// look at my code
// my code is amazing


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

int main()
{
    ll A, B;
    cin >> A >> B;
    ll K;
    if ((A + B) % 2 != 0)
    {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    if (A == B)
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        cout << (A + B) / 2 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iterator>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <sstream> 
#include <vector>
#include <cmath>
#include <map>
#include <set>

#include <queue>
#include <iomanip>
#include <functional>

using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sp system("pause");
#define MOD 998244353 
#define mxN 2005



using namespace std;


int main()
{
	fast;
	int x, y, z;
	cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x <<  " " << y << " "<<  z;
	
	return 0;
}

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

#ifdef INPUT
#include <sstream>
stringstream input(R"(
1000 1000
)");
#define cin input
#endif

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

	vector <int> vec(3);
	vec[0]=a+b;
	vec[1]=a-b;
	vec[2]=a*b;
	int max=-10000000;

	for (int i=0; i<3; i++)
	{
		if (vec[i]>max)
			max=vec[i];
	}
	cout << max << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    for a in A:
        if a == 0:
            print(0)
            return

    mul = 1
    for a in A:
        mul *= a
        if mul > 10 ** 18:
            print(-1)
            return

    print(mul)

main()


Measured memory_bytes: 84572
x1,y1,x2,y2 = map(int,input().split())
a = x2 - x1
b = y2 - y1
x3 = x2 - b
y3 = y2 + a
x4 = x1 - b
y4 = y1 + a
print(x3,y3,x4,y4)

Measured memory_bytes: 9052
#include <iostream>
#include <vector>
#include <map>
using namespace std;

class UnionFind{
private:
    vector<int> p,s;
	int cnt;
public:
	UnionFind(){}
	UnionFind(int N){
		cnt = N;
		p = s = vector<int>(N+1,0);
		for(int i=0;i<=N;i++){
			p[i] = i; s[i] = 1;
		}
	}
	int find(int x){
		if(p[x]==x) return x;
		else return p[x] = find(p[x]);
	}
	void unite(int x,int y){
		x = find(x); y = find(y);
		if(x==y) return;
		if(s[x]>s[y]) swap(x,y);
		p[x] = y;
		s[y] += s[x];
		cnt--;
	}
	bool is_same_set(int x,int y) {return find(x)==find(y);}
	int size(int x) {return s[find(x)];}
	int compnents_number(){return cnt;}
};

int N,K,L,p,q,r,s;
int main(){
    cin >> N >> K >> L;
    UnionFind uf1(N),uf2(N);
    for(int i=0;i<K;i++){
        cin >> p >> q;
        uf1.unite(p,q);
    }
    for(int i=0;i<L;i++){
        cin >> r >> s;
        uf2.unite(r,s);
    }
    map<pair<int,int>,int> m;
    for(int i=1;i<=N;i++){
        m[{uf1.find(i),uf2.find(i)}]++;
    }
    for(int i=1;i<=N;i++){
        cout << m[{uf1.find(i),uf2.find(i)}] << (i!=N? " ":"\n");
    }
}

Measured memory_bytes: 15104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using CHY72;

namespace CHY72{
    
    public class PointXY<T>where T:IComparable {
        public T X , Y;
        public bool Flag = false;
        public PointXY(T _X,T _Y) {
            X = _X; Y = _Y;
        }
        public static bool operator ==(PointXY<T> P1, PointXY<T> P2) {
            return (P1.X.CompareTo( P2.X) == 0 && P1.Y.CompareTo (P2.Y) == 0);
        }
        public static bool operator !=(PointXY<T> P1, PointXY<T> P2) {return !(P1 ==P2);}
        public override int GetHashCode() {return X.GetHashCode() ^ Y.GetHashCode();}
        public override bool Equals(object obj) {
            if (obj == null || this.GetType() != obj.GetType()) {return false;}
            return (this == (PointXY<T>)obj);
        }         

    }
    

}    

public class Program {
    static bool ReadLine_1(ref int num1, bool Fin0 = true) {
        string str = Console.ReadLine();
        num1 = int.Parse(str);
        return (Fin0 && num1 == 0);
    }
    static int  ReadLine_1() {
        return  int.Parse(Console.ReadLine());
    }
    static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true) {
        string str = Console.ReadLine();
        num1 = int.Parse(str.Split(Spliter)[0]);
        num2 = int.Parse(str.Split(Spliter)[1]);
        return (Fin0 && num1 == 0);
    }
    static int[] ReadLine72(char Spliter = ' ') {
        return Console.ReadLine().Split(Spliter).Select(s => int.Parse(s)).ToArray();
    }

    const int DefaultMax = 727272;


    static void Main(string[] args) {
        while (true) {
            int[] nmp = ReadLine72();
            if (nmp[0] == 0) return;
            int[] Xi = new int[nmp[0]];
            int BoughtNum = 0;
            for (int  i = 0; i < nmp[0]; i++) {
                BoughtNum += (Xi[i] = ReadLine_1());
            }
            int HaitouSum = BoughtNum * 100 *(100- nmp[2]) / 100;
            if (Xi[nmp[1] - 1] == 0) Console.WriteLine(0);
            else Console.WriteLine((int) (HaitouSum / Xi[nmp[1] - 1]));

        }
    }
}

Measured memory_bytes: 6028
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
amax = sorted(a)[-1]
amax2 = sorted(a)[-2]
for i in range(n):
    if a[i] == amax:
        print(amax2)
    else:
        print(amax)


Measured memory_bytes: 14660
s=list(map(str,input().split()))
stack=[]
for i in range(len(s)):
	if s[i] in "+-*":
		q1=stack.pop()
		q2=stack.pop() 
		if s[i]=="+":
			stack.append(q1+q2)
		elif s[i]=="-":
			stack.append(q2-q1)
		else:
			stack.append(q1*q2)
	else:
		stack.append(int(s[i]))
print(*stack)


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b + c >= 22 ? "bust" : "win") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;


int main() {
   int a,b;
  cin>>a>>b;
     vector<int64_t>value(a);
  for(int i=0;i<a;i++)
  {
  int64_t y;
    cin>>y;
    value.at(i)=y;
  }
  priority_queue<int64_t, vector<int64_t>, greater<int64_t>> worst;
 int64_t t=0;
  t=max(t,value.at(0));  
  t=max(t,value.at(a-1)); 
  
  
  for(int i=0;i<=a;i++)
  {
  for(int j=0;j<=a-i;j++)
  {
  int64_t f=b-i-j;
  if(f<0) continue;
   /* else if(f==0)
    {
    int64_t g=0;
    for(int64_t k=i;k<a-j;k++)
    {
    g=g+value.at(k);
     
    }
     
      t=max(t,sum-g);
    }*/
        else if(f>=0)
    {
    int64_t g=0;
       for(int64_t k=0;k<i;k++)
    {
    g=g+value.at(k);
         if(value.at(k)<0) worst.push(value.at(k));
    }
            for(int64_t k=a-j;k<a;k++)
    {
    g=g+value.at(k);
         if(value.at(k)<0) worst.push(value.at(k));
    }
          //cout<<worst.size()<<' '<<f<<' '<<g<<endl;
         
          for(int64_t i=0;i<f;i++)
          {
          if(worst.size()>0){
             //cout<<worst.top()<<endl;
            g=g-worst.top();
            worst.pop();
            
          }
            else break;
          }
      t=max(t,g);
          while(worst.size()>0) worst.pop();
         
    }
  }
  }
  cout<<t;
  
  
  
}
 

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


int main(void){
	int dice[6];
	int i,j, n;
	int top, front, right;
	int top_i, front_i;

	for(i=0; i<6; i++){
		scanf("%d", &dice[i]);
	}
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d%d", &top, &front);
		for(j=0; j<6; j++){
			if(dice[j]==top)
				top_i = j+1;
			else if(dice[j]==front)
				front_i = j+1;
		}
		if(top_i==1){
			switch (front_i) {
				case 2:	right = 3;break;
				case 3: right = 5;break;
				case 4: right = 2;break;
				case 5: right = 4;break;
			}
		} else if(top_i==2){
			switch (front_i) {
				case 6:	right = 3;break;
				case 1: right = 4;break;
				case 3: right = 1;break;
				case 4: right = 6;break;
			}
		} else if(top_i==3){
			switch (front_i) {
				case 6:	right = 5;break;
				case 1: right = 2;break;
				case 5: right = 1;break;
				case 2: right = 6;break;
			}
		} else if(top_i==4){
			switch (front_i) {
				case 1:	right = 5;break;
				case 6: right = 2;break;
				case 2: right = 1;break;
				case 5: right = 6;break;
			}
		} else if(top_i==5){
			switch (front_i) {
				case 1:	right = 3;break;
				case 6: right = 4;break;
				case 4: right = 1;break;
				case 3: right = 6;break;
			}
		} else {
			switch (front_i) {
				case 5:	right = 3;break;
				case 2: right = 4;break;
				case 4: right = 5;break;
				case 3: right = 2;break;
			}
		}
		printf("%d\n", dice[right-1]);
	}
	
	return 0;
}

Measured memory_bytes: 596
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
N,K=map(int,input().split())
blue=K
red=N-K
p=10**9+7
frac=[0]*4100
frac[0]=1
for i in range(1,4100):
    frac[i]=(frac[i-1]*i)%p
for i in range(1,K+1,1):
    if i<=red+1:
        print((frac[red+1]*modinv(frac[i],p)*modinv(frac[red+1-i],p)*frac[blue-1]*modinv(frac[i-1],p)*modinv(frac[blue-i],p))%p)
    else:
        print("0")




Measured memory_bytes: 46172
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


long long K, N;

vector<int> solve() {
	vector<int> res;
	if (K % 2 == 0) {
		res.push_back(K / 2);
		for (int i = 1; i < N; ++i) res.push_back(K);
		return res;
	}

	if (K == 1) {
		for (int i = 0; i < (N + 1) / 2; ++i) res.push_back(1);
		return res;
	}



	int d = 0;
	long long pow = 1, M = 0;
	while (pow <= N) pow *= K, ++d;
	for (int i = 0; i < N - d; ++i) res.push_back((K + 1) / 2);
	for (int i = 0; i < d; ++i) {
		M *= K;
		M += K;
	}
	long long newK = (M - (N - d) + 1) / 2 - 1;

	//COUT(d);
	//COUT(newK);

	for (int i = 0; i < d - 1; ++i) {
		long long div = 0;
		for (int j = 0; j < d - i; ++j) div *= K, div += 1;

		long long q = newK / div;
		long long r = newK % div;

		//cout << i << ": " << newK << ", " << q << ", " << r << " (" << div << ")" << endl;

		res.push_back(q + 1);
		newK = r - 1;
		if (newK < 0) break;
	}
	//COUT(newK);
	if (newK >= 0) res.push_back(newK + 1);

	return res;
}

int main() {
  while (cin >> K >> N) {
		vector<int> res = solve();
		for (int i = 0; i < res.size(); ++i) {
			cout << res[i];
			if (i != res.size() - 1) cout << " ";
		}
		cout << endl;
  }
}














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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

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

    int a, b;
    cin >> a >> b;
    if (a < b) {
        for (int i = 0; i < b; i++) {
            cout << a;
        }
        return 0;
    }
    if (a > b) {
        for (int i = 0; i < a; i++) {
            cout << b;
        }
        return 0;
    }

    for (int i = 0; i < a; i++) {
        cout << a;
    } 








    return 0;
}


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

using namespace std;

typedef long long ll;

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;
}

/*
 * ref. http://drken1215.hatenablog.com/entry/2018/06/08/210000
 *
 * usage:
 *
 * Combination *c;
 * 
 * const int MOD = 1000000007;
 * const int MAX_N = 100000;
 * 
 * int main(void) {
 *     int n, k;
 *     cin >> n >> k;
 *     c = new Combination(2 * MAX_N, MOD);
 *     cout << c->com(n + k - 1, k) << endl;
 *     delete(c);
 *     return 0;
 * }
 */
class Combination {
    public:
        const int max;
        const int mod;
        vector<ll> fac, finv, inv;

        Combination(int max, int mod) : max(max), mod(mod), fac(max), finv(max), inv(max) {
            init();
        }

        ll com(int n, int k) {
            if (n < k) return 0LL;
            if (n < 0 || k < 0) return 0LL;
            // return (fac[n] * ((finv[k] * finv[n - k]) % mod)) % mod;
            return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
        }

    private:
        void init() {
            fac[0] = fac[1] = 1;
            finv[0] = finv[1] = 1;
            inv[1] = 1;
            for (int i = 2; i < max; i++){
                fac[i] = fac[i - 1] * i % mod;
                inv[i] = mod - inv[mod%i] * (mod / i) % mod;
                finv[i] = finv[i - 1] * inv[i] % mod;
            }
        }
};

Combination *c;

const int MOD = 1000000007;
const int MAX_N = 100000;

vector<ll> x;
vector<ll> v;

int main(void) {
    c = new Combination(2 * MAX_N, MOD);
    // cout << c->com(n + k - 1, k) << endl;

    ll N;
    cin >> N;

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

    v.resize(MAX_N + 1, 0);
    for (int i = 1; i <= MAX_N; i++) {
        v[i] = (1LL * i * v[i - 1] + c->fac[i - 1]) % MOD;
    }

    ll ans = 0;
    for (int i = 1; i <= N - 1; i++) {
        ll val = v[i];
        val = val * c->fac[N - 1] % MOD;
        val = val * c->finv[i] % MOD;
        ans = (ans + (val * (x[i] - x[i - 1]) % MOD)) % MOD;
    }

    cout << ans << endl;

    delete(c);
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    ll tmp = 0;
    ll ans = 0;
    for(i = 0;i < n;++i){
        if(a.at(i) == 0){
            tmp = 0;
            continue;
        }else{
            ans += (a.at(i) + tmp)/2;
            tmp = (a.at(i) + tmp)%2;
        }
    }
    cout << ans << endl;
    return 0;
}

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

// why am I so weak

int x;

inline bool trial(int dist, int x) {
	for (int i = x; i > 0; i--) {
		if (dist - i >= 0) {
			dist -= i;
		}
	}

	return dist == 0;
}
int main() {
	cin >> x;

	int cur = 0;

	for (int i = 1; ; i++) {
		cur += i;

		if (cur >= x && trial(cur - x, i)) {
			printf("%d\n", i);
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <algorithm>
#include <cstdint>

int main() {
	using Pair = std::pair<int64_t, int64_t>;

	Pair costs[4];
	for (int64_t i = 0; i < 4; ++i) {
		std::cin >> costs[i].first;
		costs[i].first *= (1ll << (3 - i));

		costs[i].second = (1ll << i);
	}

	int64_t n;
	std::cin >> n;
	n *= 4;

	std::sort(costs, std::end(costs));

	int64_t ans = 0;
	for (auto&& p : costs) {
		if (n == 0)
			break;

		const auto c = p.first / (8 / p.second);

		ans += (n / p.second) * c;
		n %= p.second;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long int
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 1e9+7
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp);
void ipgraph(int m);
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const int mod = 1e9 + 7;
const int N = 2e5+5, M = N;
//=========================================


//int a[25][25];

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    int a[n][n];
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j)
            cin >> a[i][j];
    }

    int dp[1ll << n];
    memset(dp, 0, sizeof(dp));

    dp[0] = 1;
    for(int mask = 0; mask < (1ll << n); ++mask){
        int x = __builtin_popcount(mask);
        for(int j = 0; j < n; ++j){
            if(a[x][j] == 0 || (mask & (1ll << j))) continue;
            dp[mask|(1ll << j)] = (dp[mask|(1ll << j)] + dp[mask]) % mod;
        }
    }

    cout << dp[(1ll << n) - 1] << "\n";

    return 0;
}


Measured memory_bytes: 20032
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const lll MOD = 947352675824899;
const int N = 5e5+100;

string s, t;
ll ls, lt;
lll hs[N], ht[N], hsn[N], htn[N];
bool check(ll c){
  lll _ht = htn[c];
  c *= lt;
  ll m = c % ls;
  lll _hs = (hsn[c/ls]*modPow(27, m, MOD)+hs[m]) % MOD;
  lll d = modPow(27, c, MOD);
  FOR(i, 0, ls){
    if(_hs == _ht) return true;
    _hs = ((_hs*27 + (s[m]-'a') - d*(s[i]-'a'))%MOD+MOD)%MOD;
    m = (m+1)%ls;
  }
  return false;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s >> t;
  {
    ls = sz(s);
    lll d = modPow(27, ls, MOD);
    FOR(i, 0, ls) hs[i+1] = (hs[i]*27+s[i]-'a') % MOD;
    FOR(i, 0, N-1) hsn[i+1] = (hsn[i]*d+hs[ls]) % MOD;
  }
  {
    lt = sz(t);
    lll d = modPow(27, lt, MOD);
    FOR(i, 0, lt) ht[i+1] = (ht[i]*27+t[i]-'a') % MOD;
    FOR(i, 0, N-1) htn[i+1] = (htn[i]*d+ht[lt]) % MOD;
  }
  ll l=0, r=ls+1, m;
  while(r-l>1){
    m = (l+r)/2;
    (check(m) ? l : r) = m;
  }
  cout << (l==ls ? -1 : l) << endl;
}

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

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

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

    ll N;
    cin>>N;
    set<ll> f;
    vector<ll> edges;
    for (ll n = 0; n < N; n++) {
        ll A;
        cin>>A;
        if (f.count(A) > 0) {
            f.erase(A);
            edges.push_back(A);
        } else f.insert(A);
    }
    sort(begin(edges), end(edges), greater<>());
    if (edges.size() >= 2) cout<<edges[0] * edges[1]<<endl;
    else cout<<0<<endl;
    
    return 0;
}

Measured memory_bytes: 4992
import java.util.Collections;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int N = sc.nextInt();
			final int Q = sc.nextInt();
			
			if(N == 0 || Q == 0){
				break;
			}
			
			int[] array = new int[100];
			
			for(int i = 0; i < N; i++){
				final int M = sc.nextInt();
				
				for(int j = 0; j < M; j++){
					array[sc.nextInt()]++;
				}
			}
			
			
			int max = 0;
			int date = 0;
			for(int i = 0; i < 100; i++){
				if(array[i] >= Q && max < array[i]){
					max = array[i];
					date = i;
				}
			}
			
			System.out.println(date);
			
			/*
			ArrayList<ArrayList<Integer>> members = new ArrayList<ArrayList<Integer>>();
			HashSet<Integer> set = new HashSet<Integer>();
			
			for(int i = 0; i < N; i++){
				final int M = sc.nextInt();
				final ArrayList<Integer> list = new ArrayList<Integer>(); 
				
				for(int j = 0; j < M; j++){
					final int date = sc.nextInt();
					
					list.add(date);
					set.add(date);
				}
				
				members.add(list);
			}
			
			int max = Q - 1;
			int max_date = 0;
			for(final int i : set){
				int count = 0;
				
				for(int j = 0; j < N; j++){
					if(members.get(j).contains(i)){
						count++;
					}
				}
				
				if(count > max){
					max = count;
					max_date = i;
				}
			}
			
			System.out.println(max_date);
			*/
		}
		
	}

}

Measured memory_bytes: 12000
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll n;
int ans = 0;
vector<int> vec={3, 5, 7};

void dfs(ll c, int b) {
  if (c > n) {
    return;
  }
  if (0b111 == b) {
    ans++;
  }
  dfs(c*10 + 7, b | 0b100);
  dfs(c*10 + 5, b | 0b010);
  dfs(c*10 + 3, b | 0b001);
}


int main()
{

  cin >> n;
  
  dfs(0, 0);
  
  cout << ans << endl;
  
  
  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);
		int i = 0;

		while (true) {
			int tmp = sc1.nextInt();
			i++;
			if (tmp > 0) {
				System.out.println("Case " + i + ": " + tmp);
			}
			else break;
		}

		sc1.close();

	}

}



Measured memory_bytes: 41104
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 7;
signed main() {                
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	for (int i = 0; i < k; ++i) ans += a[i];
	cout << ans;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

long long sq(long long a)
{
    return a * a * a * a * a;
}

int main(int argc, char const *argv[])
{
    long long X;
    cin >> X;
    long long sum;
    for (long long i = -118; i <= 119; i++)
    {
        int d = 0;
        sum = 0;
        while (sum < 1000000000)
        {
            d++;
            sum = sq(i) - sq(i - d);
            if (sum == X)
            {
                cout << i << ' ' << i - d << endl;
                return 0;
            }

        }
           
    }

    cout << "ないで" << endl;
    
    return 0;
}

Measured memory_bytes: 3164