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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

using namespace std;

int main ()
{
  string S;
  int s,e;
  bool res = true;

  cin >> S;

  int N = S.size ();

  for (s=0,e=N-1;s<=e;s++,e--)
  {
    if (S[s] != S[e])
    {
      res = false;
      break;
    }
  }

  if (!res)
  {
    cout << "No\n";
    return 0;
  }  

  for (s=0,e=(N-1)/2-1;s<=e;s++,e--)
  {
    if (S[s] != S[e])
    {
      res = false;
      break;
    }
  }

  if (!res)
  {
    cout << "No\n";
    return 0;
  }

  for (s=(N+3)/2-1,e=N-1;s<=e;s++,e--)
  {
    if (S[s] != S[e])
    {
      res = false;
      break;
    }
  }

  if (res)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	cin >> s;
	if (s.size() % 2 == 1){
		if (s.front() == s.back()){
			cout << "Second" << endl;
		} else {
			cout << "First" << endl;
		}
	} else {
		if (s.front() == s.back()){
			cout << "First" << endl;
		} else {
			cout << "Second" << endl;
		}
	}
}

Measured memory_bytes: 3708
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define a first
#define b second
const int MAX = 10101;
int d[MAX];   // 頂点 1 からの 距離 を 保存.
int c[MAX];   // 与えられた正の整数.
int ans[MAX]; // 書き込み方.

// グラフを幅優先探索する.
// https://ja.wikipedia.org/wiki/幅優先探索
// ※bfsの動作確認用.
// @param G: グラフ.
// @param s: グラフの探索開始頂点.
// @param d: 探索開始地点からの距離.
// @return: 特に無し.
void bfs(vvi &G, int s, int* d){
    // 1. 空のキュー.
    queue<int> q;
    
    // 2. 訪問済みフラグ設定.
    d[s] = 0;    // スタート地点は, 距離ゼロを指定.
    
    // 3. 探索地点 s をキュー q に追加.
    q.push(s);
    while(!q.empty()){
        // 4. キューから取り出す.
        int u = q.front();
        q.pop();
        
        // 5. 取り出した要素を処理.
        for(auto &e : G[u]){
            // 6. 訪問済であれば, 処理をスキップ.
            if(d[e] > 0)            continue;
            if(d[e] == 0 && e != s) d[e] = d[u] + 1, q.push(e);
        }
    }
    return;
}

int main(){
    
    // 1. 入力情報.
    int N, a, b, sum = 0;
    scanf("%d", &N);
    vvi G(N);
    rep(i, N - 1){
        scanf("%d %d", &a, &b);
        a--, b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    rep(i, N){
        scanf("%d", &c[i]);
        sum += c[i];
    }
    
    // 2. 降順sort.
    sort(c, c + N, greater<int>());
    // rep(i, N) printf("%d ", c[i]);
    // puts("");
    
    // 3. 頂点 1 から 各頂点までの距離を計算.
    bfs(G, 0, d);
    // rep(i, N) printf("%d ", d[i]);
    // puts("");
    
    // 4. 頂点 と 距離 の ペア を 保存.
    priority_queue<P, vector<P>, greater<P>> pq;
    rep(i, N) pq.push({d[i], i}); // {距離, 頂点番号}
    
    // 5. スコアの最大値, 書き込み方は？
    int idx = -1;
    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        ans[p.b] = c[++idx];
    }
    
    // 6. 出力.
    printf("%d\n", sum - c[0]);
    rep(i, N){
        printf("%d", ans[i]);
        if(i < N - 1) printf(" ");
    }
    return 0;
    
}

Measured memory_bytes: 4364
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  vector<int> st;
  vector<int> fi;
  int n,t;
  int c,m;
  string T;
  while(1){
    c=0;
    m=0;
    st.erase(st.begin(),st.end());
    fi.erase(fi.begin(),fi.end());
    //
    cin >> n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin >> T;
      t=(T[0]-'0')*36000+(T[1]-'0')*3600+(T[3]-'0')*600+(T[4]-'0')*60+(T[6]-'0')*10+T[7]-'0';
      st.push_back(t);
      cin >> T;
      t=(T[0]-'0')*36000+(T[1]-'0')*3600+(T[3]-'0')*600+(T[4]-'0')*60+(T[6]-'0')*10+T[7]-'0';
      fi.push_back(t);
    }
    sort(st.begin(),st.end());
    sort(fi.begin(),fi.end());
    int i1=0,i2=0;
    while(1){
      if(st[i1]<fi[i2]){
	i1++;
	c++;
	m=max(m,c);
	if(i1==n)break;
      }
      else{
	i2++;
	c--;
	if(i2==n)break;
      }
    }
    cout << m << endl;
  }
  return 0;
}

Measured memory_bytes: 3188
N = int(input())
L = []
for _ in range(N):
    a, b = map(int, input().split())
    L.append((a, b, a+b))
L.sort(key=lambda x:x[2])
# L = deque(L)
# print(L)
score = 0
while True:
    if not L:
        break
    score += L.pop()[0]
    if not L:
        break
    score -= L.pop()[1]
print(score)

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int m = max(A, max(B, C));
    int ans = A + B + C - m;
    rep(i, K) m *= 2;
    cout << ans + m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int n,m;
	cin>>n>>m;
	ll num[9]={2,5,5,4,5,6,3,7,6}, dp[n+1],a[m];
	rep(i,m)cin>>a[i];
	sort(a,a+m);

	rep(i,n+1)dp[i]=-1000000;
	dp[0]=0;
	rep(i,n){
		rep(j,m){
			if(dp[i]>=0 && i+num[a[j]-1]<=n && dp[i+num[a[j]-1]]<dp[i]+1)dp[i+num[a[j]-1]]=dp[i]+1;
		}
	}


	rep(i,m){
		while(n>=num[a[m-1-i]-1] && dp[n-num[a[m-1-i]-1]]+1 == dp[n]){
			cout<<a[m-1-i];
			n-=num[a[m-1-i]-1];
		}
	}
	
	cout<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
vector<int> V[maxn];
map<int,int>M[maxn];
struct node
{
	int x,y;
}edg[maxn];
int main()
{
	int n,m,x,y;
	scanf("%d%d",&n,&m);
	for(int i = 0 ; i < m ; i++)
	{
		scanf("%d%d",&x,&y);
		edg[i].x = x , edg[i].y = y;
		V[x].push_back(y); 
	}
	for(int i = 1 ; i <= n ; i++) sort(V[i].begin() , V[i].end());
	for(int i = 1 ; i <= n ; i++)
	{
		int cnt = 0;
		for(auto j : V[i])
		{
			M[i][j] = ++cnt;
		}
	}
	for(int i = 0 ; i < m ; i++)
	{
		int p = M[edg[i].x][edg[i].y];
		printf("%06d%06d\n",edg[i].x,p);
	}
}

Measured memory_bytes: 17152
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int a;
	in >> N>>a;
	out << N*N - a << endl;
	return 0;
}
#endif

#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;
int32_t K;
int32_t X[200];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>K;
	int64_t res = 0;
	for (int32_t i = 0; i < N; i++)
	{
		int a;
		in >> a;
		res += std::min(K - a, a);
	}
	out << res*2 << endl;
	return 0;
}
#endif


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();


		if(N%10==0 || N%10==1 || N%10==6 || N%10==8) {
			System.out.println("pon");
		}else if(N%10==3) {
			System.out.println("bon");
		}else {
			System.out.println("hon");
		}


	}
}


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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

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

	int a, b, c;
	cin >> a >> b >> c;
	cout << c << ' ' << a << ' ' << b << '\n';
}


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

using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
 
template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

const int INF = 1e9;
int h, w;

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

bool moze(int x, int y)
{
    return x >= 0 && y >= 0 && x < w && y < h;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> h >> w;
    int ch, cw;
    cin >> ch >> cw;
    --ch, --cw;
    int dh, dw;
    cin >> dh >> dw;
    --dh, --dw;

    vector<string> v(h);
    for(auto &z : v)
        cin >> z;

    vvi dist(h, vi(w, INF));

    dist[ch][cw] = 0;

    deque<pii> dq;
    dq.pb({ch, cw});
    while(!dq.empty())
    {
        auto tren = dq.front();
        dq.pop_front();

        for(int k = 0; k < 4; ++k)
        {
            int novoX = tren.se + dx[k], novoY = tren.fi + dy[k];

            if(moze(novoX, novoY) && v[novoY][novoX] == '.' && (dist[novoY][novoX] == INF || dist[tren.fi][tren.se] < dist[novoY][novoX]))
            {
                dist[novoY][novoX] = dist[tren.fi][tren.se];
                dq.push_front({novoY, novoX});
            }
        }

        for(int i = tren.se-2; i <= tren.se+2; ++i)
        {
            for(int j = tren.fi-2; j <= tren.fi+2; ++j)
            {
                if(!moze(i, j))
                    continue;
                if(v[j][i] == '.' && dist[j][i] == INF)
                {
                    dist[j][i] = dist[tren.fi][tren.se] + 1;
                    dq.pb({j, i});
                }
            }
        }
    }

    cout << ((dist[dh][dw] == INF) ? -1 : dist[dh][dw]) << "\n";
}


Measured memory_bytes: 8700
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int main(){
  int n,m;
  cin>>n;
  map<string,int> mp;
  rep(i,n){
    string a;
    cin>>a;
    mp[a]++;
  }
  cin>>m;
  rep(i,m){
    string a;
    cin>>a;
    mp[a]--;
  }
  int ans=0;
  auto itr = mp.begin();
  for(;itr!=mp.end();itr++){
    ans=max(ans,itr->second);
  }
  cout<<ans<<endl;



}


Measured memory_bytes: 256
/*
  GOOD is not Enough
  You've got to be GREAT.
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

void solve()
{
   long double a,b;
   cin >> a >> b;
   long double ans=floor(a*b);
   cout << (int)ans << '\n';
  return;
} 

signed main()
{
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3744
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double debt = 100000;
    for(int i=0; i<n; i++) {
      debt *= 1.05;
      if(debt % 1000 != 0) {
        debt = (Math.floor(debt/1000)+1)*1000;
      }
      else {
        debt = Math.floor(debt);  
      } 
    }    
    System.out.println((int)debt);
  }
}

Measured memory_bytes: 25996
#include<bits/stdc++.h>
using namespace std;
char s[100009];
int main()
{
    int sg=0;
    int sp=0;
    int sum=0;
    scanf("%s",&s);
    int n=strlen(s);
    for(int i=0;i<n;i++)
    {
        if(sg==sp)
        {
            sg++;
            if(s[i]=='p')
            {
                sum--;
            }
        }
        else if(sg>sp)
        {
            if(s[i]=='g')
            {
                sp++;
                sum++;
            }
            else if(s[i]=='p')
            {
                sp++;
            }
        }

    }
    cout<<sum<<endl;
}


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

int parent(int i){
    return i/2;
}

int left(int i){
    return i*2;
}

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

void maxHeapify(int A[], int i, int n){
    int l = left(i);
    int r = right(i);
    // 左の子、自分、右の子で値が最大のノードを選ぶ
    int largest;
    if(l <= n && A[l] > A[i])
        largest = l;
    else 
        largest = i;
    
    if(r <= n && A[r] > A[largest])
        largest = r;

    if(largest != i){  // i の子の方が値が大きい場合
        swap(A[i], A[largest]);
        maxHeapify(A, largest, n); // 再帰的に呼び出し
    }
}

void insert(int num, int A[], int &n){
    A[++n] = num;
    for(int i=n; i>1; i/=2){
        if(A[i] > A[i/2]){
            swap(A[i], A[i/2]);
        }
    }
}

int extract(int A[], int &n){
    if(n < 1){
        return -INT_MAX;
    }
    int tmp = A[1];
    swap(A[1], A[n]);
    n--;
    maxHeapify(A, 1, n);
    
    return tmp;
}

int main() {

    int a[MAX];
    int n = 0;
    
    while(1){
        string command;
        cin >> command;
        if(command == "insert"){
            int num;
            cin >> num;
            insert(num, a, n);
        }
        else if(command == "extract"){
            cout << extract(a, n) << endl;
        }
        else if(command == "end"){
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 7104
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in(x) cin>>x
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
using pl = vector<pair<ll,ll>>;
using ps = vector<pair<string,ll>>;
const double pi = 3.14159265358979;

int main() {
ll N;
  cin >> N;
vl T(N);
  rep(i,N) in(T[i]);
  ll M;
  in(M);
  pl P(M);
  rep(i,M){
   int p,x;
    cin >>p>>x;
    P[i] = mp(p,x);
  }
  rep(i,M){
   int ans =0;
    rep(j,N){
     if(P[i].F == j+1) ans += P[i].S;
      else ans += T[j];
    }
 out(ans);
  }
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[110];
int b[11];
int sz;
int expr(int a);
int cur;
char s[10]="01+-*().";
int u[110];
int term(){
	if(str[cur]=='('){
		cur++;
		int ret=expr(cur);
		if(str[cur]!=')')return -1;
		
		cur++;
		return ret;
	}else if('0'<=str[cur]&&str[cur]<='1'){
		int ret=0;
		while(str[cur]=='0'||str[cur]=='1'){
			ret*=2;
			ret+=str[cur]-'0';
			cur++;
			if(ret>=1024)return -1;
		}
		return ret;
	}else return -1;
}
int fact(int a){
	int ret=term();
	if(ret==-1)return -1;
	while(1){
		if(str[cur]=='0')return -1;
		if(str[cur]=='1')return -1;
		if(str[cur]=='(')return -1;
		if(str[cur]!='*')break;
		cur++;
		u[a]++;
		int tmp=term();
		if(tmp==-1)return -1;
		ret*=tmp;
		if(ret<0||ret>=1024)return -1;
	}
	return ret;
}
int expr(int a){
	int ret=fact(a);
	if(ret==-1)return -1;
	while(1){
		if(str[cur]=='0')return -1;
		if(str[cur]=='1')return -1;
		if(str[cur]=='(')return -1;
		if(str[cur]!='+'&&str[cur]!='-')break;
		char ch=str[cur];
		u[a]++;
		cur++;
		int tmp=fact(a);
		if(tmp==-1)return -1;
		if(ch=='+')ret+=tmp;
		else ret-=tmp;
		if(ret<0||ret>=1024)return -1;
	}
	return ret;
}
int solve(int a){
	if(a==sz){
		cur=0;
		int left=0;
		for(int i=0;str[i];i++)u[i]=0;
		int ret=expr(0);
		for(int i=0;str[i];i++)if(str[i]=='('&&u[i+1]==0)return -1;
		if(str[cur])return -1;
		return ret;
	}
	int ret=-1;
	for(int i=0;i<7;i++){
		str[b[a]]=s[i];
		ret=max(ret,solve(a+1));
	}
	return ret;
}
int main(){
	scanf("%s",str);
	for(int i=0;str[i];i++){
		if(str[i]=='.')b[sz++]=i;
	}
	printf("%d\n",solve(0));
}

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

bool f(int n)
{
    if(n==0) return true;
    else if(n<0) return false;
    return f(n-4) || f(n-7);
}

int main()
{
   int n;cin>>n;
   cout<<(f(n) ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define endl            "\n"
#define forn(i,x1,n)     for(int i=x1; i<n; i++)
#define forit(it, m)    for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x1)      __builtin_popcountll(x1)
#define zrobits(x1)      __builtin_ctzll(x1)
#define mod             1000000007
#define inf             1e18
#define ps(x1,y)         fixed<<setprecision(y)<<x1
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x1)            int x1; cin>>x1; while(x1--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


void zeus()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {

    zeus();

    int n; cin >> n;

    int a[n];

    forn(i, 0, n) {
        cin >> a[i];
    }
    int ans = 0;
    forn(i, 1, n) {
        if (a[i] < a[i - 1]) {
            ans += (a[i - 1] - a[i]);
            a[i] = a[i - 1];
        }
    }

    cout << ans << endl;



}








Measured memory_bytes: 5220
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
//	tmp = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);
    var A =[];
    A.push(a);

    for (i=1;i<1000000;i++){
    if (a%2 == 0){a=a/2;}
           else{a=a*3+1;}
          var p=A.indexOf(a);
           if ( p!==-1){console.log(i+1);
                       　break;}
           A[i]=a;

    }
    //console.log(A);
	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
H, W, K = map(int, input().split())
HW = [[0] * W for i in range(H)]
S = [0] * H
for i in range(H):
  x = str(input())
  for j in range(len(x)):
    HW[i][j] = int(x[j])
#print(HW) 

for i in range(H):
  S[i] = sum(HW[i])
#print(S)  

ans = H + W
for i in range(2 ** (H - 1)):#521 * 9
  time = 0
  now = 0
  cut = []
  for j in range(H - 1):
    if (i >> j) & 1:#j番目とj+1番目の間で割る
      cut.append(j)
  #print(cut)
  cut2 = [[] for _ in range(len(cut) + 1)]
  for j in range(len(cut)):
    for p in range(now, cut[j] + 1):
      cut2[j].append(p)
      now = cut[j] + 1
  for p in range(now, H):
    cut2[-1].append(p)
  #print(cut2)    
    
  time = len(cut2) - 1  
  choco = [0] * len(cut2)
  for l in range(W):
    for k in range(len(cut2)):
      nn = 0
      for p in cut2[k]:
        nn += HW[p][l]
      if nn > K:  
        time += 10000
      else:
        choco[k] += nn
      

    if max(choco) > K: 
      time += 1
      for k in range(len(cut2)):
        nn = 0
        for p in cut2[k]:
          nn += HW[p][l]
        choco[k] = nn  

  ans = min(ans, time)
  #print(i, time)
  
print(ans)     
      
    

Measured memory_bytes: 74984
#include <iostream>
#include <cmath>
#define AMAX 1000000000
#define NMAX 1000000
#define MMAX 100
#define SERIES(id) ((pow(3,((id)+1))-1)/2)
using namespace std;

// 一定間隔gを空けた要素について挿入ソート
int insertionSort(int *A, int n, int g) {
    int cnt = 0;
    for (int i=g; i<n; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
    return cnt;
}

// A: ソートされる配列
// n: 配列Aの要素数
void shellSort(int *A, int n, int *G, int *retVal) {
    int m;
    for (int i=0; i<MMAX; i++) {
        if ( SERIES(i) > n ) {
            m = i;
            break;
        }
    }
    for (int i=0; i<m; i++) {
        G[i] = SERIES(m-i-1);
    }

    int cnt = 0;
    for (int i=0; i<m; i++) {
        cnt += insertionSort( A, n, G[i] );
    }
    retVal[0] = m;
    retVal[1] = cnt;
}

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

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

    // solve
    int G[MMAX];
    int retVal[2];
    shellSort(A, n, G, retVal);
    int m = retVal[0];
    int cnt = retVal[1];

    // output
    cout << m << endl;
    for (int i=0; i<m; i++) {
        cout << G[i];
        if (i == m-1) {
            cout << endl;
        } else cout << " ";
    }
    cout << cnt << endl;
    for (int i=0; i<n; i++) {
        cout << A[i] << endl;
    }
}


Measured memory_bytes: 7112
n,m = map(int, input().split())
if m <= n:
  print(0)
  exit()
xx = list(map(int, input().split()))
xx.sort()
sub_x = [0]*(m-1)
for i, (front, end) in enumerate(zip(xx[:-1],xx[1:])):
  sub_x[i] = end - front
sub_x.sort()
print(sum(sub_x[:m-n]))

Measured memory_bytes: 13960
def resolve():
    S = list(input())
    ans = [0 for _ in range(len(S))]
    rcnt, lcnt = 0, 0
    border = None
    for i in range(len(S)):
        #print("[{}], {}, {}".format(i, rcnt, lcnt))
        if i == 0:
            rcnt += 1
            continue

        # R -> L
        if S[i-1]=="R" and S[i] == "L":
            border = i
        # L -> R
        elif S[i-1]=="L" and S[i] == "R":
            ans[border-1] += rcnt//2 + lcnt//2
            ans[border] += rcnt//2 + lcnt//2
            if rcnt%2==1:
                ans[border-1] += 1
            if lcnt%2==1:
                ans[border] += 1
            rcnt, lcnt = 0, 0
            border = None
        
        if S[i] == "R":
            rcnt += 1
        else:
            lcnt += 1
    ans[border-1] += rcnt//2 + lcnt//2
    ans[border] += rcnt//2 + lcnt//2
    if rcnt%2==1:
        ans[border-1] += 1
    if lcnt%2==1:
        ans[border] += 1
    print(*ans)


if '__main__' == __name__:
    resolve()


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

m = a[-1]

r = 10**10
for i in range(n):
    if abs(a[i]-(m-a[i])) < r:
        r = abs(a[i]-(m-a[i]))
        idx = i

print(m, a[idx])


Measured memory_bytes: 14428
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
typedef long long ll;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	cout << pow(n,3) << endl;
	return 0;
}


Measured memory_bytes: 512
from sys import stdin

n, *a = map(int, stdin.read().split()) 

l_count = {}
for l in a:
    l_count.update({l: l_count.get(l, 0) + 1})
  
long_side, short_side = 0, 0
for l, c in sorted(l_count.items(), reverse=1):
    if c != 1:
        if not long_side:
            if c >= 4:
                print(l ** 2)
                exit()
            else:
                long_side = l
        else:
            short_side = l
            break

print(long_side * short_side)

Measured memory_bytes: 20956