akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
#include <cassert>
#include <climits>
#include <cmath>

using namespace std;
using namespace chrono;

// 0以上UINT_MAX未満(0xffffffff)をとる乱数 xorshift https://ja.wikipedia.org/wiki/Xorshift
static uint32_t randXor()
{
    static uint32_t x = 123456789;
    static uint32_t y = 362436069;
    static uint32_t z = 521288629;
    static uint32_t w = 88675123;
    uint32_t t;

    t = x ^ (x << 11);
    x = y; y = z; z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

// 0以上1未満をとる乱数
static double rand01()
{
    return (randXor() + 0.5) * (1.0 / UINT_MAX);
}

const static int NUM_TYPES = 26; // コンテストの種類数

// 全体のスコア（今回の問題のスコア）
static int getFullScore(const int D, const vector <int>& C, const vector <int>& T, const vector<vector<int>>& S)
{
    int score = 0;

    vector <int> last(NUM_TYPES, 0);

    for (int d = 0; d < D; d++)
    {
        const int j = T[d];
        last[j] = d + 1;
        for (int t = 0; t < NUM_TYPES; t++)
        {
            score -= (d + 1 - last[t]) * C[t];
        }
        score += S[d][j];
    }

    return score;
}

int main()
{
    auto startClock = system_clock::now();

    //  入力
    int D;
    cin >> D;
    vector<int> C(NUM_TYPES);
    for (int &c : C)
    {
        cin >> c;
    }

    vector<vector<int>> S(D, vector<int>(NUM_TYPES));
    for (auto &s : S)
        for (auto &x : s)
        {
            cin >> x;
        }

    vector<int> T(D);   // T[d] d日目に開くコンテスト
    for (int d = 0; d < D; d++)
    {
        T[d] = d % NUM_TYPES;
    }

    int score = getFullScore(D, C, T, S);   // 現在のスコア
    int bestScore = INT_MIN;    // 最高スコア
    vector <int> bestT;         // 最高スコアを出したときのT

    const static double START_TEMP  = 1500; // 開始時の温度
    const static double END_TEMP    =  100; // 終了時の温度
    const static double END_TIME    =  1.8; // 終了時間（秒）

    double temp = START_TEMP;   // 現在の温度

    long long steps;    // 何回まわったか
    for (steps = 0; ; steps++)
    {
        const double time = duration_cast<microseconds>(system_clock::now() - startClock).count() * 1e-6;   // 経過時間（秒）
        if (time >= END_TIME)
        {
            break;
        }

        const double progressRatio = time / END_TIME;   // 進捗。開始時が0.0、終了時が1.0
        temp = START_TEMP + (END_TEMP - START_TEMP) * progressRatio;

        // 近傍1 : d日目のコンテストをtに変えてみる
        const int d = randXor() % D;
        const int t = randXor() % NUM_TYPES;
        const int backupT = T[d];
        int deltaScore = 0;

        deltaScore -= getFullScore(D, C, T, S);
        T[d] = t;
        deltaScore += getFullScore(D, C, T, S);

        if (exp(deltaScore / temp) > rand01())
        {
            score += deltaScore;
            if (score > bestScore)
            {
                bestScore = score;
                bestT = T;
            }
        }
        else
        {
            T[d] = backupT;
        }
    }

    // 出力
    for (int t : bestT)
    {
        cout << t + 1 << endl;
    }
    cerr << "steps: " << steps << endl;
    cerr << "bestScore: " << max(0, bestScore + 1000000) << endl;

    return 0;
}


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

int main(){
	int n;	cin>>n;
	int min=1000,max=0;

	int x;
	for(int i=0;i<n;i++){

		cin>>x;
		if(x<min)min=x;
		if(x>max)max=x;
	}

	cout<<max-min<<endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0]*3 for _ in range(n+1)]
dp[1] = abc[0]
for i in range(1,n):
  dp[i+1][0] = max(dp[i][1],dp[i][2])+abc[i][0]
  dp[i+1][1] = max(dp[i][0],dp[i][2])+abc[i][1]
  dp[i+1][2] = max(dp[i][0],dp[i][1])+abc[i][2]
  
print(max(dp[-1]))

Measured memory_bytes: 47692
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ull n,t,s=0;
    cin>>n>>t;
    int a[n];
    s+=t;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=1;i<n;i++)
    {
        ll dt = a[i]-a[i-1];
        if(dt<=t) s+=dt;
        else s+=t;
    }
    cout<<s<<endl;
    return 0 ; 
}

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

bool arimasuka(vector<string> &map,int y,int x){
  
  bool c=false;
  if(x>=0 && x<map.at(0).size() && y>=0 && y<map.size() && map.at(y).at(x) == '#'){
    c=true; return c;}
  else{return c;}  
  
}



void bomb_count(vector<string> &map,int y,int x){
  
  int sum=0;
  if(map.at(y).at(x) == '#') return;
  else if(map.at(y).at(x) == '.'){
    
    if(arimasuka(map,y+1,x-1)) sum++;
    if(arimasuka(map,y+1,x)) sum++;
    if(arimasuka(map,y+1,x+1)) sum++;
    if(arimasuka(map,y,x-1)) sum++;
    if(arimasuka(map,y,x+1)) sum++;
    if(arimasuka(map,y-1,x-1)) sum++;
    if(arimasuka(map,y-1,x)) sum++;
    if(arimasuka(map,y-1,x+1)) sum++;
    
    if(sum == 0){map.at(y).at(x)='0'; return;}
    else if(sum == 1){map.at(y).at(x)='1'; return;}
    else if(sum == 2){map.at(y).at(x)='2';return;}
    else if(sum == 3){map.at(y).at(x)='3';return;}
    else if(sum == 4){map.at(y).at(x)='4';return;}
    else if(sum == 5){map.at(y).at(x)='5';return;}
    else if(sum == 6){map.at(y).at(x)='6';return;}
    else if(sum == 7){map.at(y).at(x)='7';return;}
    else if(sum == 8){map.at(y).at(x)='8';return;}
    else{return;}
  }
}
 
int main() {
  int H, W; cin >> H >> W;
  vector<string> map(H);
  for(int i=0;i<H;i++){
      cin >> map.at(i);
  }
  
  for(int j=0;j<H;j++){
    for(int k=0;k<W;k++){
      bomb_count(map,j,k);
    }
  }
  
  for(int l=0;l<H;l++){
      cout << map.at(l) << endl;
  }
}  

Measured memory_bytes: 256
import java.util.*;

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

	public Main() {
		new AOJ0028().doIt();
	}
	
	class AOJ0028{
		void doIt(){
			int[] index = new int[101];
			while(in.hasNext())index[in.nextInt()]++;
			int max = 0;
			for(int i=0;i<101;i++)max = Math.max(max, index[i]);
			for(int i=0;i<101;i++)if(max==index[i])System.out.println(i);
		}
	}
}

Measured memory_bytes: 18356
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MAX_N = 100000 + 1;
ll a[MAX_N];
ll b[MAX_N];

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

  int n;
  cin >> n;

  map<int, int> mp1, mp2;
  
  for (ll i = 0; i < int(n/2); i++) {
    cin >> a[i] >> b[i];

    if(mp1.find(a[i]) == mp1.end()) mp1[a[i]] = 1;
    else mp1[a[i]]++;

    if(mp2.find(b[i]) == mp2.end()) mp2[b[i]] = 1;
    else mp2[b[i]]++;
    
  }

  int cnt = 0;

  vector<P> v1, v2;
  
  for (auto itr = mp1.begin(); itr != mp1.end(); itr++) {
    P p = P(itr->second, itr->first);
    v1.push_back(p);
  }

  for (auto itr = mp2.begin(); itr != mp2.end(); itr++) {
    P p = P(itr->second, itr->first);
    v2.push_back(p);
  }

  sort(v1.begin(), v1.end(), greater<P>() );
  sort(v2.begin(), v2.end(), greater<P>() );

  int ans;
  if (v1[0].second != v2[0].second) {
    ans = n - v1[0].first - v2[0].first;
  }
  else {
    ans = min(n - v1[0].first - v2[1].first, n - v1[1].first - v2[0].first);
  }
    
  cout << ans << endl;
  return 0;
}





Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main(){
    int n;
    ll ans=0;
    cin >> n;
    rep(i,n){
        int a;
        cin >> a;
        while(a%2==0){
            a/=2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main() {
    stack<int> s1;
    stack<pair<int, int> > s2;
    int sum = 0;
    char ch;
    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\') {
            s1.push(i);
        }
        else if(ch == '/' && !s1.empty()) {
            int j = s1.top();
            s1.pop();
            sum += i - j;
            int a = i - j;
            while (s2.size() > 0 && s2.top().first > j) {
                a += s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(j, a));
        }
    }
    vector<int> ans;
    while (s2.size() > 0) {
        ans.push_back(s2.top().second);
        s2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++) {
        cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3184
#include<iostream>
#include<string>
using namespace std;
string a,b,c,ans;
bool ok(int s)
{
	for(int i=s;i<s+b.length();i++)
	{
		if(a[i]!='?'&&a[i]!=b[i-s])
			return false;
	}
	return true;
}
string replace(int s,int e)
{
	string temp;
	temp=a;
	for(int i=s;i<=e;i++)
	{
		temp[i]=b[i-s];
	}
	return temp;
}
int main()
{
	int t=0;
	cin>>a>>b;
	int la=a.length(),lb=b.length();
	for(int i=0;i<=la-lb;i++)
	{
		string c=a;
		if(ok(i))
		{
			c=replace(i,i+lb-1);
//			cout<<c<<endl;
			if(t==0)
			{
				ans=c;t++;
			}
			else
			{
				if(ans>c) ans=c; 
			}
		}
	}
	if(ans=="")
	{
		cout<<"UNRESTORABLE";return 0;
	}
	for(int i=0;i<=ans[i]!='\0';i++)
	{
		if(ans[i]=='?')
			cout<<'a';
		else
			cout<<ans[i];
	}	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int N, L;
	string A[N];
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	string S;
	for (int i = 0; i < N; i++) {
		S += A[i];
	}
	cout << S << endl;

}

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

const long long mod=1e9+7;
int n;
long long a[100010],ni[100010],s[100010],ans,jie[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	scanf("%lld",&a[i]);
	ni[1]=1;
	for(int i=2;i<=n;++i)
	ni[i]=(mod-mod/i)*ni[mod%i]%mod;
	for(int i=1;i<=n;++i)
	s[i]=(s[i-1]+ni[i])%mod;
	for(int i=1;i<=n;++i)
	ans=(ans+s[n-i+1]*a[i]%mod+(s[i]-1)*a[i]%mod)%mod;
	jie[0]=1;
	for(int i=1;i<=n;++i)
	jie[i]=jie[i-1]*i%mod;
	ans=(ans*jie[n])%mod;
	printf("%lld\n",ans);
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        ret %= MOD;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}



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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int n;
map<string,bool> mp;
vector<string> ans;
void dfs(string res, int p){
  if(mp[res]) return;
  mp[res]=true;
  if(res.size()==n){
    ans.push_back(res);
    return ;
  }
  rep(i,p){
    char c='a'+i;
    if(c=='p'){
      cout<<p<<endl;
    }
    if(i==p-1) dfs(res+c,p+1);
    else dfs(res+c,p);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n;
  
  dfs("a",2);
  vsort(ans);
  rep(i,ans.size()){
    cout<<ans[i]<<endl;
  }
  // cout<<ans.size()<<endl;
}

Measured memory_bytes: 18292
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	int ans = 0;
	cin >> n;
	while (n--)
	{
		int x;
		cin >> x;
		ans += x - 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

ll wh = 0, bl = 0;
void bfs(int a, int b, vector<vector<char>> &grid,vector<vector<bool>> &vi) {
    int H = grid.size(), W = grid[0].size();
    int tate[4] = { -1,0,1,0 }, yoko[4] = { 0,1,0,-1 };
    if (grid[a][b] == '.') wh++;
    else bl++;
    for (int i = 0; i < 4; i++) {
        int c = a + tate[i], d = b + yoko[i];
        if (c<0 || c>H - 1 || d<0 || d>W - 1) continue;
        if (vi[c][d]) continue;
        if (grid[c][d] == grid[a][b]) continue;
        vi[c][d] = true;
        bfs(c, d, grid, vi);
    }
}
int main() {
    int H, W; cin >> H >> W;
    vector<vector<char>> grid(H,vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++)
            cin >> grid[i][j];
    }
    vector<vector<bool>> vi(H, vector<bool>(W));
    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            vi[i][j] = true;
            bfs(i, j, grid, vi);
            ans += wh * bl;
            wh = 0, bl = 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 22912
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b;
  cin>>a>>b;
  int c=a+b;
  if(c%2==0)
    cout<<c/2<<endl;
  else
    cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a;
    cin >> a;
    if (a >= 1200)
        cout << "ARC";
    else
    {
        cout << "ABC";
    }

    return 0;
}

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

    typedef long long ll;
    typedef pair<int, int> ii;

    #define Canuc80k cin.tie(0); cout.tie(0);
    #define FOR(i,a,b) for (int i=a;i<=b;i++)
    #define FORD(i,a,b) for (int i=a;i>=b;i--)
    #define I_AM ios_base::sync_with_stdio(0);
    #define FORS(i,a,b,c) for (int i=a;i<=b;i+=c)
    #define FORSD(i,a,b,c) for (int i=a;i>=b;i-=c)

    const ll N = 1e6 + 1;
    const ll M = 1e9 + 7;

    int v[N], w[N], f[101][N];
    int n, m;

    int cal(int pos, int weight) {
        if (pos == n + 1) return 0;
        if (f[pos][weight] != -1) return f[pos][weight];

        int temp = 0;
        if (weight + w[pos] <= m) 
            temp = max(temp, cal(pos + 1, weight + w[pos]) + v[pos]);
        temp = max(temp, cal(pos + 1, weight));
        
        f[pos][weight] = temp;
        return temp;
    }

    int main() {
        I_AM Canuc80k

        cin >> n >> m;
        FOR (i, 1, n) 
            cin >> v[i] >> w[i];

        FOR (i, 0, n) 
            FOR (j, 0, m)
                f[i][j] = -1;

        cal(1, 0);

        // FOR (i, 0, n) 
        //     FOR (j, 0, m)
        //         cout << i << " " << j << " " << f[i][j] << endl;

        cout << f[1][0] << endl;
    }


Measured memory_bytes: 7572
main :: IO ()
main = do
  s <- getLine
  let
    solve _ [] = (-1, -1)
    solve _ [_] = (-1, -1)
    solve n [x, y] = if x == y then (n, n+1) else (-1, -1)
    solve n (x:y:z:xs)
      | x == y = (n, n+1)
      | x == z = (n, n+2)
      | otherwise = solve (n+1) (y:z:xs)
  putStrLn $ (\(x, y) -> show x ++ " " ++ show y) $ solve 1 s


Measured memory_bytes: 7548
N = int(input())
n_list = list(map(int, input().split()))

i_tmp = 0
swap_list = []
for i in n_list:
    if i - i_tmp != 1:
        swap_list.append(i)
    i_tmp += 1

if (len(swap_list) == 0) or (len(swap_list) == 2):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 2000000
int H,A[MAX+1];

void maxHeapify(int i){
  int l,r,largest,tmp;
  l=2*i;
  r=2*i+1;

  if(l<=H&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H&&A[r]>A[largest]) largest=r;

  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}
int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++) scanf("%d",&A[i]);
  for(i=H/2;i>=1;i--) maxHeapify(i);
  for(i=1;i<=H;i++) printf(" %d",A[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 2552
#include <iostream>
#include <math.h>
#include <queue>
using namespace std;

int main(void){
    
    int N, M;
    vector<priority_queue<int>> q;
    priority_queue<long long> q1;
    priority_queue<long long> q2;
    priority_queue<long long> q3;
    priority_queue<long long> q4;
    priority_queue<long long> q5;
    priority_queue<long long> q6;
    priority_queue<long long> q7;
    priority_queue<long long> q8;
    
    cin >> N >> M;
    
    long long x, y ,z;
    for ( int i = 0; i < N; i++ ) {
        cin >> x >> y >> z;
        
        q1.push( x + y + z);
        q2.push( -x + y + z);
        q3.push( x -y + z);
        q4.push( -x -y + z);
        q5.push( x + y -z);
        q6.push( -x + y -z);
        q7.push( x -y -z);
        q8.push( -x -y -z);
    }
    
    long long a1=0, a2=0, a3=0, a4=0, a5=0, a6=0, a7=0, a8=0;
    
    for ( int i = 0; i < M; i++ ) {
        a1 += q1.top(); q1.pop();
        a2 += q2.top(); q2.pop();
        a3 += q3.top(); q3.pop();
        a4 += q4.top(); q4.pop();
        a5 += q5.top(); q5.pop();
        a6 += q6.top(); q6.pop();
        a7 += q7.top(); q7.pop();
        a8 += q8.top(); q8.pop();
    }
    
    a1 = max(a1,a2);
    a3 = max(a3,a4);
    a5 = max(a5,a6);
    a7 = max(a7,a8);
    
    a1 = max(a1,a3);
    a5 = max(a5,a7);
    
    cout << max( a1,a5 ) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<long long> a(n);

    long long sum = 0;

    for (auto& x : a) {
        scanf("%d", &x);
        sum += x;
    }

    long long bestAns = sum;

    long long curSum = 0;
    for (const auto x : a) {
        curSum += x;
        const auto cur = abs(sum - curSum - curSum);
        if (cur < bestAns) {
            bestAns = cur;
        }
    }

    cout << bestAns << endl;
}

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

using namespace std;

#define int long long

const int N = 405, inf = 1e18 + 123;
int n, a[N], dp[N][N];

int32_t main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i], a[i] += a[i - 1];

    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) dp[i][j] = inf;
    for (int i = 1; i <= n; ++i) dp[i][i] = 0;

    for (int dist = 1; dist < n; ++dist) {
        for (int i = 1; i + dist <= n; ++i) {
            int j = i + dist;
            for (int k = i; k < j; ++k) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + a[j] - a[i - 1]);
        }
    }

    cout << dp[1][n];

    return 0;
}


Measured memory_bytes: 1536
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,k = li()
x = list(li())

ans = 10**18

for st in range(n-k+1):
    ed = st+k-1
    cand = max(abs(x[st]), abs(x[ed]))
    if x[st] * x[ed] < 0:
        cand += 2 * min(abs(x[st]), abs(x[ed]))
        
    ans = min(ans,cand)
    
print(ans)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

void insert(int );
void inorder(Node );
void preorder(Node );
Node treeSearch(Node , int);

Node root;

Node treeSearch(Node u, int k){
    while(u != NIL && k != u->key){
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

    while(x != NIL){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;

    if(y == NIL) root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;
}

void inorder(Node u){
    if(u != NIL){
        inorder(u->left);
        printf(" %d",u->key);
        inorder(u->right);
    }
}
void preorder(Node u){
    if(u != NIL){
        printf(" %d",u->key);
        preorder(u->left);
        preorder(u->right);
    }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
        /*
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      */
    }
  }

  return 0;
}



Measured memory_bytes: 20452
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 998244353
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int x,y;
	cin>>x>>y;
	int ans = 0;
	if( x == 1 )ans += 300000;
	if( x == 2 )ans += 200000;
	if( x == 3 )ans += 100000;
	if( y == 1 )ans += 300000;
	if( y == 2 )ans += 200000;
	if( y == 3 )ans += 100000;
	if( x == 1 && y == 1 ) ans += 400000;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
ans = np.zeros(n)
base = []
for i in range(2):
  base.append(list(map(int,input().split())))

ans[0] = base[0][0]
for i in range(n):
  ans[0] += base[1][i]
  
for i in range(1,n):
  ans[i] = ans[i-1] - base[1][i-1] + base[0][i]
  
print(int(np.max(ans)))

Measured memory_bytes: 12396
#include <stdio.h>

char S[100000];

int main () {

        scanf("%s", S);

        int count_odd = 0;
        int count_even = 0;

        int i = 0;
        int s = 1;
        do {
                if (s == 1 && S[i] == '0')
                        count_odd++;
                else if (s == -1 && S[i] == '1')
                        count_odd++;
                else
                        count_even++;
                s *= -1;

        } while (S[++i]);

        if (count_odd < count_even)
                printf("%d\n", count_odd);
        else
                printf("%d\n", count_even);

        return 0;
}


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

using namespace std;

const int MAX_W = 1005, MAX_H = 1005;
const int inf = 1e+9;

int w, h, C;
char G[MAX_H][MAX_W];
int sx, sy, ex, ey;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
struct P{int x,y;};
int d[MAX_H][MAX_W];

int bfs(char e){
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            d[i][j] = inf;
        }
    }
    queue<P> que;
    que.push((P){sx, sy});
    d[sx][sy] = 0;
    while(!que.empty()){
        P p = que.front();que.pop();

        if(G[p.x][p.y] == e) {
            ex = p.x;
            ey = p.y;
            break;
        }

        for(int i = 0;i < 4;i++){
            int nx = p.x + dx[i], ny = p.y + dy[i];
            if(0<=nx && nx<h && 0<=ny && ny<w && G[nx][ny]!='X' && d[nx][ny] > d[p.x][p.y]+1){
                d[nx][ny] = d[p.x][p.y] + 1;
                que.push((P){nx, ny});
            }
        }
    }
    sx = ex;
    sy = ey;
    return d[ex][ey];
}

void solve(){
    int sum = 0;
    for(int i = 1;i <= C;i++){
        sum+=bfs(i+'0');
    }
//    for(int i = 0;i <h;i++){
//        for(int j = 0;j <w;j++){
//            cout<<d[i][j]<<' ';
//        }
//        cout<<endl;
//    }
    printf("%d\n", sum);
}

int main(){
    scanf("%d%d%d", &h, &w, &C);

    for(int i = 0;i < h;i++){
        scanf("%s", G[i]);
    }

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(G[i][j] == 'S'){
                sx = i;
                sy = j;
            }
        }
    }

//    for(int i = 0;i <h;i++){
//        for(int j = 0;j <w;j++){
//            cout<<G[i][j]<<' ';
//        }
//        cout<<endl;
//    }
        solve();

    return 0;
}

/*
3 3 1
S..
...
..1

4 5 2
.X..1
....X
.XX.S
.2.X.
 */


Measured memory_bytes: 8176
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int ans,N,k,m;
cin>>N>>k;
ans=1;
if(N<k){
	ans=1;
}
else {
	m=N%k;
	if(m==0) ans=0;
}

	
cout <<ans<<endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

struct UnionFind{
    
    vector<ll> par;
    
    UnionFind(ll N) : par(N){
        for(ll i = 0; i < N; i++) par.at(i) = i;
    }
    
    ll root(ll x){
        ll px = par.at(x);
        if(x == px) return x;
        return par.at(x) = root(px); 
    }
    
    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return;
        par.at(rx) = ry;
    }
    
    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
    
};


int main(void){
    ll N, M;
    cin >> N >> M;
    
    vector<ll> p(N);
    for(ll i = 0; i < N; i++){
        cin >> p.at(i);
    }
    
    UnionFind num(N);
    
    ll tmpa, tmpb;
    for(ll i = 0; i < M; i++){
        cin >> tmpa >> tmpb;
        num.unite(tmpa-1, tmpb-1);
    }
    
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        if(num.same(p.at(i)-1, i)){
            ans++;
        }
    }
    printf("%lld\n", ans);
    
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
constexpr int kInf = 1e9;

int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  int cnt_blk = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      char c; cin >> c;
      if (c == '.') {
        A[i][j] = kInf;
      } else {
        A[i][j] = -1;
        ++cnt_blk;
      }
    }
  }

  A[0][0] = 0;
  queue<pair<int, int>> que;
  que.push({0, 0});
  while (!que.empty()) {
    auto p = que.front(); que.pop();
    int r = p.first;
    int c = p.second;
    vector<pair<int, int>> ds = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    for (auto& d : ds) {
      int nr = r + d.first;
      int nc = c + d.second;
      if (nr < 0 || H <= nr || nc < 0 || W <= nc) continue;
      if (A[nr][nc] > A[r][c] + 1) {
        A[nr][nc] = A[r][c] + 1;
        que.push({nr, nc});
      }
    }
  }

  if (A[H-1][W-1] == kInf) cout << -1 << endl;
  else cout << H * W - A[H-1][W-1] - cnt_blk - 1 <<  endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
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 vi          vector<int>
#define vii         vector<pii>
#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 mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
 
/*---------------------------------------------------------------------------------------------------*/
 
void solve()
{
    int n;
    cin >> n;
    int x, y;
    int key;

    int cnt = 0;
    string ans = "No";
    f(i, n)
    {
        cin >> x >> y;

        if (x != y)
        {
            cnt = 0;
        }
        else
        {
            cnt++;
        }

        if (cnt == 3)
        {
            ans = "Yes";
        }
    }

    cout << ans;

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll INF = ~(1<<31);
#define fs first
#define sc second
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
    return (a % b + b) % b;
}

struct node {
    ll val;
    node() {
        val = 0;
    }
    node(ll _val) { val = _val; };
    node(node a, node b) {
        val = max(a.val, b.val);
    }
};
struct segment_tree {
    ll sz, n;
    vector<node> t;
    segment_tree(ll _n) : sz(_n*4), n(_n) {
        rep(i,0,sz) t.pb(node());
    }
    void build(vi &a, ll v=1, ll tl=0, ll tr=-1) {
        if(tr == -1) tr = n-1;
        if(tl == tr) {
            t[v].val = a[tl];
        } else {
            ll tm = (tl+tr)/2;
            build(a, v*2, tl, tm);
            build(a, v*2+1, tm+1, tr);
            t[v] = node(t[v*2],t[v*2+1]);
        }
    }
    node query(ll l, ll r, ll v=1, ll tl=0, ll tr=-1) {
        if(tr == -1) tr = n-1;
        if(l > r) return node();
        if(l == tl && r == tr) return t[v];
        ll tm = (tl+tr)/2;
        return node( query(l,min(r,tm), v*2, tl, tm)
                ,query(max(l,tm+1), r, v*2+1, tm+1, tr));

    }
    void update(ll pos, ll new_val, ll v=1, ll tl=0, ll tr=-1) {
        if(tr == -1) tr = n-1;
        if(tl == tr) t[v].val = new_val;
        else {
            ll tm = (tl+tr)/2;
            if(pos <= tm) update(pos, new_val, v*2, tl, tm);
            else update(pos, new_val, v*2+1, tm+1, tr);
            t[v] = node(t[v*2], t[v*2+1]);
        }
    }
};

int main() {
    cin.sync_with_stdio(false);
    ll n;
    cin >> n;
    segment_tree sq(n);
    vi A(n);
    vi B(n);
    rep(i,0,n) cin >> A[i], A[i]--;
    rep(i,0,n) cin >> B[i];
    for(ll i = n-1; i >= 0; i--) {
        ll val = sq.query(A[i], n-1).val;
        sq.update(A[i], val + B[i]);
    }
    cout << sq.query(0,n-1).val << endl;
    return 0;
}



Measured memory_bytes: 11496
#include <bits/stdc++.h>  
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
ll l=1000000007;
string alphabet="abcdefghijklmnopqrstuvwxyz";

int main() {
  string s; cin>>s;
  if(s.size()!=26){
    cout<<s;
    rep(i,26){
      if(count(s.begin(),s.end(),alphabet[i])==0){
        cout<<alphabet[i]; break;
      }
    }
  }
  else{
    if(s=="zyxwvutsrqponmlkjihgfedcba"){cout<<-1;}
    else{
      rep(i,25){
        if(s[25-i]>s[24-i]){
          rep(j,24-i){cout<<s[j];}
          for(int j=25; j>=25-i; j--){
            if(s[j]>s[24-i]){cout<<s[j]; break;}
          }
          break;
        }
      }
    }
  }
 
}

Measured memory_bytes: 3580
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
}



Measured memory_bytes: 256
w, h, n = map(int, input().split())
xya = []

left = 0
right = w
under = 0
upper = h

for _ in range(n):
    x, y, a = map(int, input().split())

    if a==1:
        left = max(x, left)
    elif a==2:
        right = min(x, right)
    elif a==3:
        under = max(y, under)
    else:
        upper = min(y, upper)

if (upper-under)>0 and (right-left)>0:
    ans = (upper-under)*(right-left)
    print(ans)
else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define sz(a) (int)a.size()
#define int long long

using namespace std;

int a[200010];
int sl[200010];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i= 0; i < n; i++) {
        cin >> a[i];
    }
    int cnt = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] == 0)
            cnt++;
        else
            cnt = 0;
        sl[i] = cnt;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int s1 = 0, s2 = 0;
        int k = i;
        while (k < n) {
            if (sl[k] != 0) {
                if (s1 == s2) {
                    ans += sl[k];
                }
                k += sl[k];
            }
            if (k >= n)
                break;
            s1 += a[k];
            s2 ^= a[k];
            if (s1 == s2)
                ans++;
            if (s1 > s2)
                break;
            k++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int h, w, ans;
char c[514][514];
bool used[514][514];
int wh, br;
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int dfs(int x, int y) {
	c[x][y] == '.' ? wh++ : br++;
	used[x][y] = true;
	rep(i, 4) {
		int xx = x + dx[i], yy = y + dy[i];
		if (xx < 0 || xx >= h || yy < 0 || yy >= w)continue;
		if (c[x][y] != c[xx][yy] && !used[xx][yy]) {
			dfs(xx, yy);
		}
	}
	return 0;
}
signed main() {
	cin >> h >> w;
	rep(i, h)rep(j, w)cin >> c[i][j];
	rep(i, h) {
		rep(j, w) {
			if (!used[i][j]) {
				wh = 0, br = 0;
				dfs(i, j);
				ans += br * wh;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 8192
#include<stdio.h>
int main(void)
{
	int a,b,m,i,n,x,y,z;
	x=0;
	y=0;
	z=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d %d",&a,&b);
		if(a>=n){
			x=0;
		}
		if(a<n){
			x=n-a;
		}
		if(y<x){
			y=x;
		}
		z=z+x;
	}
	z=z-y;
	printf("%d\n",z);
	
	return 0;
}



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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

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

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) (x).erase(unique(all(x)), (x).end())
#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int n, ans = 1;
    cin >> n;
    REP(i, 1, n + 1)
    {
        ans = i * ans % inf;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<string,vector<int> > sv;
map<vector<int>,string > vs;
map<string,string> ss;
vector<int> dfs();
int n,m,inp,d,p,f;
string s,t,t2;
bool ans;

vector<int> get(){
  vector<int> res(n);
  res[0]=(1e9);
  if(s[p]=='(')p++,res=dfs(),p++;
  else{
    string str;
    while(('a'<=s[p]&&s[p]<='z')||('A'<=s[p]&&s[p]<='Z'))str+=s[p++];
    res=sv[ss[str]];
  }
  return res;
}

vector<int> cal(){
  vector<int> res=get(),r;
  while(s[p]!=')'){
    if(s[p]=='*'){
      p++;
      r=get();
      for(int i=0;i<n;i++)res[i]+=r[i];
    }
    else if(s[p]=='/'){
      p++;
      r=get();
      for(int i=0;i<n;i++)res[i]-=r[i];
    }else break;
  }
  return res;
}

vector<int> dfs(){
  vector<int> res=cal(),r(n);
  r[0]=(1e9);
  while(p<s.size()&&s[p]!=')'){
    if(s[p]=='+'||s[p]=='-')p++;
    else r=cal();
    if(r[0]!=(1e9)&&res!=r)ans=false;
  }
  return res;
}

int main(){
  while(1){
    cin>>n>>m>>inp;
    if(!n&&!m&&!inp)break;
    for(int i=0;i<m;i++){
      cin>>t;
      for(int j=0;j<n;j++){
	cin>>d;
	sv[t].push_back(d);
      }
      vs[sv[t]]=t;
    }
    cin>>s;
    for(int i=0;i<inp;i++){
      cin>>t>>t2;
      ss[t]=t2;
    }
    s='('+s+')'; p=0;
    ans=true;
    vector<int> r=dfs();
    if(!ans)cout<<"error"<<endl;
    else if(vs.count(r))cout<<vs[r]<<endl;
    else cout<<"undefined"<<endl;
    sv.clear();
    vs.clear();
    ss.clear();
  }
  return 0;
}

Measured memory_bytes: 3164
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            while(n!=0){
                int[] cards = new int[n];
                for (int i = 0; i < cards.length; i++) {
                    cards[i] = cards.length - i ;
                }
                int r = sc.nextInt();
                for (int i = 0; i < r ; i++) {
                    int p = sc.nextInt();
                    int c = sc.nextInt();
                    int[] tmpcards = new int[p-1];

                    for (int j = 0; j < p-1; j++) {
                        tmpcards[j] = cards[j] ;
                    }

                    for (int j = 0; j < c; j++) {
                        cards[j] = cards[j + p - 1] ;
                    }

                    for (int j = 0; j < p-1; j++) {
                        cards[j+c] = tmpcards[j] ;
                    }
                }
                System.out.println(cards[0]);
                n = sc.nextInt();
            }
        }
    }
}



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

ll po(ll b, ll e) {
  if(e==0) return 1;
  if(e%2==0) {
    ll t = po(b,e/2);
    return t*t;
  }
  return b*po(b,e-1);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll n,a,b;
  cin>>n>>a>>b;
  if(n==1) {
    if(a==b) {
      cout << 1 << endl;
      return 0;
    }
    cout << 0 << endl;
    return 0;
  }
  if(b>=a)
    cout << (n-2)*(b-a)+1 << endl;
  else
    cout << 0 << endl;
  return 0;
}


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

int n,x,y,z,mx,ji;
const long long mod=1e9+7;
long long ans,dp[45][1000010];
int main()
{
	scanf("%d%d%d%d",&n,&x,&y,&z);
	ans=1;
	for(int i=1;i<=n;++i)
	ans=ans*10%mod;
	mx=(1<<(x+y+z))-1;
	ji=(1<<(x+y+z-1));
	ji|=(1<<(y+z-1));
	ji|=(1<<(z-1));
	dp[0][0]=1;
	for(int i=1;i<=n;++i)
	{
		for(int j=0;j<=mx;++j)
		{
			if(dp[i-1][j]==0)
			continue;
			for(int k=1;k<=10;++k)
			{
				int cur=(j<<k)|(1<<(k-1));
				cur&=mx;//只取后(x+y+z)位
				if((cur&ji)==ji)
				continue;
				dp[i][cur]=(dp[i][cur]+dp[i-1][j])%mod; 
			}
		}
	}
	for(int i=0;i<=mx;++i)
	ans=(ans-dp[n][i]+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 121088
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 200000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
// clang-format on
int N;
int A[MAX_N];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  REP(i, N) cin >> A[i];
  set<int> st;
  REP(i, N) {
    if (st.count(A[i]) > 0) {
      cout << "NO" << endl;
      return 0;
    }
    st.insert(A[i]);
  }
  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 10368
//chokudai
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int N, K;
vector<int> Nums;
vector<int> Sums;
string S;

int main() {
    cin >> N >> K;
    cin >> S;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] == (char)('0' + now)) cnt++;
        else {
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0) Nums.push_back(cnt);

    if (Nums.size() % 2 == 0) Nums.push_back(0);

    int Add = 2 * K + 1;

    Sums.resize(Nums.size() + 1);
    for (int i = 0; i < Nums.size(); ++i) {
        Sums[i + 1] = Sums[i] + Nums[i];
    }

    int ans = 0;
    int tmp = 0;

    for (int i = 0; i < Nums.size() ; i += 2) {

        int left = i;
        int right = min(i + Add, (int)Nums.size());
        
        tmp = Sums[right] - Sums[left];

        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1272