akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    double height = x / (double)(a * b) * 2;
    double balpha = 0, bb = (double)b;
    if(height > a){
        balpha = (2 * (x / (double)a) / (double)a) - b;
        bb -= balpha;
        //printf("%.6lf %.6lf %.6lf\n", balpha, bb, height);
        height = a;
    }
    double ratio = height/(double)bb;
    double theta = atan(ratio);
    double thetadeg = theta * 360.0 / (2 * PI);
    //printf("%.6lf\n", height);
    //printf("%.6lf\n", ratio);
    //printf("%.6lf\n", theta);
    printf("%.6lf\n", 90 - thetadeg);
    return 0;
}

Measured memory_bytes: 512
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
const int N=1401;
int M[N][N],dp[N][N],h,w;
int solve(){
	int ans=0;
	for(int i=0;i<=h;i++) M[i][0]=1; 
	for(int i=0;i<=w;i++) M[0][i]=1;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(M[i][j]) dp[i][j]=0;
			else{
				dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1;
				ans=max(ans,dp[i][j]);
			}
	return ans*ans;
}
int main(){
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) scanf("%d",&M[i][j]);
	printf("%d\n",solve());
} 


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> nn(n);
  rep(i, n) nn[i] = i + 1;

  ll res = 0;
  for (int nnn : nn) {
    if (nnn % 3 == 0 && nnn % 5 == 0) {
    } else if (nnn % 3 == 0) {
    } else if (nnn % 5 == 0) {
    } else {
      res += nnn;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 7116
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define int ll
typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}


int h,w;


int calc(int x , int y){
    int s1,s2,s3=0;
    int x1,x2;
    int sa = h*10;
    rep(i,x){
        x1 = i;
        x2 = x-x1;
        s3 = 0;
        
        if(x2%2 == 0){
            s1 = x1*y;
            s2 = x2/2*y;
        }else if(y%2 == 0){
            s1 = x1*y;
            s2 = x2*y/2;
        }else{
            int edge = max(x2,y);
            s1 = x1*y;
            s2 = x2*(edge/2);
            s3 = h*w - s1-s2;
        }
        
        if(s3 ==0){
            sa = min(sa, abs(s1-s2));
        }else{
            sa = min(sa, max(s1,max(s2,s3))-min(s1,min(s2,s3)));
        }
    }
    
    return sa;
}

signed main(){
    
    cin >> h >> w;
    
    
    int ans = h*10;
    
    ans = min(calc(h,w),calc(w,h));
    
    cout << ans << endl;
    
    
    
    
}





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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root,NIL;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x=x->left;
      return x;
}

Node treeMaximum(Node x){
while(x->right!=NIL)
  x=x->right;
      return x;
}

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

Node treeSuccessor(Node x){
  if(x->right!=NIL)
    return treeMinimum(x->right);

 Node  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right==NIL) y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL) x=y->left;
  else x=y->right;

  if(x!=NIL) x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if (y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;
  if(y!=z) z->key=y->key;

  free(y);
}

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) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node u){
if(u==NIL) return;
    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: 20524
#include <iostream>
#include <algorithm>
#include <list>
using namespace std;

pair<int,char> card[9];

int main(void){
	int t;
	cin >> t;
	for(int loop=0;loop<t;loop++){

		for(int i=0;i<9;i++)
			cin >> card[i].first;

		for(int i=0;i<9;i++)
			cin >> card[i].second;

		bool ok=false;

		sort(card,card+9);

		do{	
			bool check=true;

			for(int i=0;i<3;i++){
				bool color=false;

				// color
				if(((card[3*i].second==card[3*i+1].second)&&(card[3*i+1].second==card[3*i+2].second)))
					color=true;

				bool number=false;

				// number
				if((card[3*i].first+1==card[3*i+1].first)&&(card[3*i+1].first+1==card[3*i+2].first))
					number=true;
				
				if((card[3*i+1].first==card[3*i].first)&&(card[3*i+2].first==card[3*i+1].first))
					number=true;

				if(number&&color)
					continue;

				check=false;
			}

			if(check)
				ok=true;

		}while(next_permutation(card,card+9));
		cout << ok <<  endl;
	}
	return 0;
}

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

const int MOD = 1000000000 + 7;
const int MAX = 2000000;

long long combination(long long N_, long long R_) {
    const int NUM_ = MAX;
    static long long fact[NUM_+1], invfact[NUM_+1], mod_inv[NUM_+1];
    fact[0] = fact[1] = invfact[0] = invfact[1] = mod_inv[1] = 1;
    for (int i = 2; i < NUM_; i++) {
        if (i > N_ && i > R_) break;
        fact[i] = fact[i - 1] * i % MOD;
        mod_inv[i] = mod_inv[MOD % i] * (MOD - MOD / i) % MOD;
        invfact[i] = invfact[i - 1] * mod_inv[i] % MOD;
    }
    return fact[N_] * invfact[R_] % MOD * invfact[N_-R_] % MOD;
}

int main() {
    int x,y;
    cin >> x >> y;

    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int count = (x + y) / 3;
    int n = y - count;
    int m = x - count;

    if (n < 0 || m < 0) {
        cout << 0 << endl;
        return 0;
    }

    cout << combination(n + m, n) << endl;
    
    return 0;
}


Measured memory_bytes: 20736
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;


vector<pair<double , double> > cor;

int factrial (int n) {
  if(n == 0) return 1;
  else return n*factrial(n-1);
}

int main() {
  int N,M;
  cin >> N >> M;
  int cor[M];
  rep(i,M) {
    cin >> cor[i];
  }
  int dif[N-1];
  sort(cor,cor+M);
  rep(i,M-1) {
    dif[i] = cor[i+1] - cor[i];
  }
  sort(dif,dif+M-1);

  int ans = 0;
  rep(i,M-N) {
    ans += dif[i];
  }
  cout << ans << endl;

  return 0;
}










Measured memory_bytes: 3908
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vpi vector<pair<int,int> >
#define ll long long 
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
// #define mod 998244353
#define mod 1000000007
#define MAXN  1000001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



void solve()
{
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int t;
    // cin>>t;
    t = 1;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 256
tap = gets.chomp.chars
odds = ['R', 'U', 'D']
evens = ['L', 'U', 'D']

check = true
tap.each.with_index(1) do |t, i|
  check =
    if i.odd?
      odds.include? t
    else
      check = evens.include? t
    end
  break unless check
end

puts check ? 'Yes' : 'No'

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main() {

    long long N, K;
    cin >> N >> K;

    long long res = N % K;
    N = res;
    if(res == 0)
    {
        cout << "0" << endl;
        return 0;
    }

    while(res > abs(N - K))
    {
        N = abs(N - K);
        res = N;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int ma(int a,int b)
{
    if(a>b)
    return a;
    else
    {
        return b;
    }
    
}
int main()
{
    int n;
    cin>>n;
    int arr[n][3];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    int max[3][n];
    max[0][0]=arr[0][0];
    max[1][0]=arr[0][1];
    max[2][0]=arr[0][2];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(j==0)
            max[j][i]=ma(max[1][i-1]+arr[i][0],max[2][i-1]+arr[i][0]);
            if(j==1)
            max[j][i]=ma(max[0][i-1]+arr[i][1],max[2][i-1]+arr[i][1]);
            if(j==2)
             max[j][i]=ma(max[1][i-1]+arr[i][2],max[0][i-1]+arr[i][2]);
        }
    }
    int res=INT16_MIN;
    for(int i=0;i<3;i++)
    {
        if(max[i][n-1]>res)
          res=max[i][n-1];
    }
    cout<<res;
    return 0;
}

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

void DisplayArray(int A[], int N)
{
    int i;
    for (i = 0; i < N; i++) {
        if (i) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void InsertionSort(int A[], int N)
{
    int v, i, j;
    for (i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        DisplayArray(A, N);
    }
}

int main(void)
{
    int N, i;
    scanf("%d%*c", &N);
    int* A = (int*)malloc(sizeof(int) * N);

    for (i = 0; i < N; i++) scanf("%d", &A[i]);
    scanf("%*c");

    DisplayArray(A, N);
    InsertionSort(A, N);

    return 0;
}

Measured memory_bytes: 604
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef long long ll;
const int MAX_N=100;
int N;

struct Vector{
	ll x,y;
	Vector(ll x=0,ll y=0):x(x),y(y){}
	Vector operator + (const Vector &v){
		return Vector(x+v.x,y+v.y);
	}
	Vector operator - (const Vector &v){
		return Vector(x-v.x,y-v.y);
	}
};
typedef Vector Point;
Point hol[MAX_N];
double lb[MAX_N],ub[MAX_N];

int main(){
	cin>>N;
	REP(i,N){
		ll x,y;
		cin>>x>>y;
		hol[i]=Point(x,y);
	}
	REP(i,N){
		vector<double> ang;
		REP(j,N){
			if (i==j) continue;
			Point v=hol[i]-hol[j];
			swap(v.x,v.y);
			v.x*=-1;
			double theta=atan2((double)v.y,(double)v.x);
			if (theta<0.0){
				theta+=2*M_PI;
			}
			ang.push_back(theta);
		}
		sort(ang.begin(),ang.end());
		lb[i]=ang[0],ub[i]=lb[i]+M_PI;
		FOR(j,1,N-1){
			if (ang[j]<=ub[i]){
				lb[i]=ang[j];
			}else{
				ub[i]=min(ub[i],ang[j]-M_PI);
			}
		}
	}
	REP(i,N){
		printf("%.8f\n",max(ub[i]-lb[i],0.0)/2/M_PI);
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long a, b,c,d;
    cin >> a >> b >> c >> d;
    long long ans=LONG_LONG_MIN;
    ans = max(a*c, ans);
    ans = max(a*d, ans);
    ans = max(b*c, ans);
    ans = max(b*d, ans);
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e3 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[1005][1005];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> x >> y;
     x *= y;
     if(x % 2 == 0)
     {
         cout << "Even";
         return 0;
     }
     cout << "Odd";
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>

using namespace std;

char map[100][100];
char smap[100][100];
int ans;

int serch(int nx,int ny,int maxx,int maxy)
{
	int nextx[4]={1,0,-1,0},nexty[4]={0,1,0,-1};
	map[ny][nx]='0';
/*///////////////ツ確ツ認ツ用////////////////////	
	getchar();
	
	system("cls");
	
	cout << "nowx:" << nx << " mowy:" << ny << "maxx:" << maxx << " maxy:" << maxy << endl;
	cout << maxx << " " << maxy << endl;
	for(int i=0;i<maxy;i++)
	{
		for(int j=0;j<maxx;j++)
		{
			cout << smap[i][j];
		}
		cout << endl;
	}
	cout << endl;
	for(int i=0;i<maxy;i++)
	{
		for(int j=0;j<maxx;j++)
		{
			cout << map[i][j];
		}
		cout << endl;
	}
*//////////////////////////////////////////	
	for(int i=0;i<4;i++)
	{
		if(0<=nx+nextx[i] && nx+nextx[i]<maxx && 0<=ny+nexty[i] && ny+nexty[i]<maxy &&map[ny+nexty[i]][nx+nextx[i]]=='.')
		{
//				cout << "nextx:" << nx+nextx[i] << " nexty:" << ny+nexty[i] << endl;
				serch(nx+nextx[i],ny+nexty[i],maxx,maxy);
		}
	}
	return ans++;
}

int main()
{
	int x,y;
	int i,j;
	int sx,sy;
	
	for(;;)
	{
		cin >> x >> y ;
		
		if(x==0 && y==0)
			break;
		
		for(i=0;i<y;i++)
		{
			for(j=0;j<x;j++)
			{
				cin >> map[i][j];
				smap[i][j]=map[i][j];
				if(map[i][j]=='@')
				{
					sx=j;
					sy=i;
				}
			}
		}
		
		ans=0;
		serch(sx,sy,x,y);
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <ctype.h>

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int ch;

    ch = getchar ( );
    putchar ( toupper ( ch ) );

    if ( ch == '\n' ) break ;
  }

  return ( 0 );
}

Measured memory_bytes: 0
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     int n,x,t;cin>>n>>x>>t;
     if(n<=x){
         cout<<t<<endl;
         return;
     }
     else{
         int ans=t;
         n -= x;
         if(n%x){
             ans = ans + ((n/x)*t) + t;
         }
         else{
             ans += ((n/x)*t);
         }
         cout<<ans<<endl;
     }
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 3648
N = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append((i + n // i) - 2)
            if i != n // i:
                divisors.append((n // i + i) - 2)

    divisors.sort()
    return divisors


div = make_divisors(N)
print(min(div))


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

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

const ll MOD = 1000000007;

ll N;

ll mpow(ll a, ll n){
    if(n == 0) return 1;
    ll r = mpow(a, n/2);
    r *= r; r %= MOD;
    if(n % 2) r *= a;
    return r % MOD;
}

int main(){
    //freopen("in.txt", "r", stdin);
    cin>>N;
    cout<<(((mpow(10, N) + mpow(8, N) - mpow(9, N)*2)%MOD+MOD)%MOD)<<endl;
    return 0;
}


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

int main(void){
	int N;
	cin >> N;
	int H[N];
	for(int i=0;i<N;i++) cin >> H[i];
	
	int ans=1;
	for(int i=1;i<N;i++){
		int count=0;
		for(int j=0;j<i;j++){
			if(H[j]<=H[i]) count++;
		}
		if(count==i) ans++;
	}
	cout << ans;
}

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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

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

const int N = (int)1e5 + 123, inf = 1e9;
const ll INF = 1e18;

ll n, a[N], b[N];
ll s, k;
int main(){
	scanf("%d", &n);
	k = n * (n + 1) / 2;
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		s += a[i];
	}
	if(s % k != 0){
		puts("NO");
		return 0;
	}
	s /= k;
	for(int i = 0; i < n; i++)
		b[i] = a[(i + 1) % n] - a[i] - s;
	for(int i = 0; i < n; i++){
		if(b[i] > 0 || b[i] % n != 0){
			puts("NO");
			return 0;
		}
		s += b[i] / n;
	}
	if(s == 0)
		puts("YES");
	else
		puts("NO");
	return 0;
}


Measured memory_bytes: 1792
n = gets.to_i
ba = Array.new(10000+1,0)
for i in 1..100
  for j in 1..100
    for k in 1..100
      s = i*i + j*j + k*k + i*j + j*k + k*i
      if s < 10001
        ba[s] += 1
      end
    end
  end
end
n.times do |i|
  puts ba[i+1]
end

Measured memory_bytes: 14380
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;


string change(string s,string add,int order)
{
    if(order==0)
    {
        s=add+s;
    }
    else
    {
        s+=add;
    }
    return s; 
}

int main()
{
    string s;
    cin>>s;
    
    ll q;
    cin>>q;
    int order=1;
    string front;
    rep(i,q)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            
                order=(order+1)%2;
            
        }
        else
        {
            int f;
            char c;
            cin>>f>>c;
            f--;
            if(f==0)
            {
                if(order==0)
                {
                    s.push_back(c);
                }
                else
                {
                    front.push_back(c);
                }
                
            }
            else
            {
                if(order==0)
                {
                    front.push_back(c);
                }
                else
                {
                    s.push_back(c);
                }
                
            }
            
        }
        
    }
    if(order==1)
    {
        reverse(front.begin(),front.end());
        cout<<front+s;

    }
    else
    {
        reverse(s.begin(),s.end());
        cout<<s+front;
    }
    

        
}

Measured memory_bytes: 1248
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};
const main=()=>{
  let S=ts()
  for(let i=0;i<(1<<3);i++){
    let s=S.split('')
    if(i&1<<0)s[0]+='+'
    else s[0]+='-'
    if(i&1<<1)s[1]+='+'
    else s[1]+='-'
    if(i&1<<2)s[2]+='+'
    else s[2]+='-'
    if(eval(s.join(''))==7){
      to(s.join('')+'=7')
      return
    }
  }
}
main()


Measured memory_bytes: 7500
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        1000000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

template<typename T>
T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class EBomber {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, m, k, Cmaxi = 0, Rmaxi = 0;
        in >> n >> m >> k;
        vector<int> row(n + 2), colum(m + 2);
        set<pair<int, int>> s;
        for (int i = 0; i < k; ++i) {
            int x, y;
            in >> x >> y;
            row[x]++;
            colum[y]++;
            Cmaxi = max(Cmaxi, colum[y]);
            Rmaxi = max(Rmaxi, row[x]);
            s.insert({x, y});
        }
        vector<int> co;
        for (int i = 1; i < m + 1; ++i) {
            if (colum[i] == Cmaxi) {
                co.push_back(i);
            }
        }
        for (int i = 1; i < n + 1; ++i) {
            if (row[i] == Rmaxi) {
                for (int t : co) {
                    if (s.find({i, t}) == s.end()) {
                        out << Rmaxi + Cmaxi << endl;
                        return;
                    }
                }
            }
        }
        out << Rmaxi + Cmaxi - 1 << endl;
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    EBomber solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

int main(){
    ll a,b,c,x,y; cin>>a>>b>>c>>x>>y;
    ll ans = 0;

    while(x>0 && y>0 && (2*c) < a+b){
        ans += 2*c;
        x--;
        y--;
    }

    while(x > 0){
        ans += min(2*c,a);
        x--;
    }

    while(y > 0){
        ans += min(2*c,b);
        y--;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
hell 0 = 100000
hell n = p5 $ ((hell (n-1)) * 105) `div` 100

p5 n
  | mod n 1000 == 0 = n
  | otherwise       = 1000 * ((div n 1000) + 1)

main = do
  s <- readLn
  print $ hell s

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  vector<string> a(100);
  cin>>h>>w;
  for(int i=0; i<h; i++)
    cin>>a.at(i);
  
  for(int i=0; i<w+2; i++)
    cout<<"#";
  cout<<endl;
  
  for(int i=0; i<h; i++)
    cout<<"#"<<a.at(i)<<"#"<<endl;;
  
  for(int i=0; i<w+2; i++)
    cout<<"#";
  cout<<endl;
}

Measured memory_bytes: 256
from sys import stdin
import collections
import math
import itertools

n,m,r   = [int(x) for x in stdin.readline().rstrip().split()]
r_arr = [int(x) for x in stdin.readline().rstrip().split()]

ways = [[int(c)  for c in stdin.readline().rstrip().split()] for _ in range(m)]
inf = float('inf')
cost = [[inf] * n for _ in range(n)]
for i in range(n):
    cost[i][i] = 0

for way in ways:
    cost[way[0]-1][way[1]-1] = way[2]
    cost[way[1]-1][way[0]-1] = way[2]


# ワーシャルフロイド
for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

# rの訪れ方を全パターン試して、最小の距離のものを答えにする。
tours = []
for perm in itertools.permutations(r_arr):
    d = 0
    for i in range(r-1):
        d += cost[perm[i]-1][perm[i+1]-1]
    tours.append(d)
print(min(tours))

Measured memory_bytes: 70748
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int X = A * N;
        
        if(X < B){
            System.out.println(X);
        } else {
            System.out.println(B);
        }
        
        sc.close();
        
    }
}


Measured memory_bytes: 20948
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){
  string S; cin >> S;
  ll K; cin >> K;

  if (S.length() == 1){
    cout << K / 2 << endl;
  }else{

  vector <int> cnt;
  int num = 1;
  for (int i = 0; i < S.length() - 1; i++){
    if (S[i] == S[i + 1]){
      num++;
    }else{
      cnt.push_back(num);
      num = 1;
    }
  }
  if(num > 1) cnt.push_back(num);

  ll C = 0;
  for (int i = 0; i < cnt.size(); i++){
    C += cnt[i] / 2;
  }
  
  bool D = false;
  if (S[0] == S[S.length() - 1] && cnt[0] % 2 == 1 && cnt[cnt.size() - 1] % 2 == 1){
    D = true;
  }
  
  if (cnt.size() == 1){
    ll L = S.length() * K;
    cout << L / 2 << endl;
  }else if (D == false){
    cout << C * K << endl;
  }else{
    cout << C * K + K - 1 << endl;
  }
  
  }

  return 0;
}


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

int main() {
	string S;
	int QN;
	cin >> S >> QN;

	string front = "";
	string rear = "";
	bool rev = false;

	for (int i = 0; i < QN; i++) {
		int op;
		cin >> op;
		if (op == 1) rev = !(rev);
		else {
			int a; char b;
			cin >> a >> b;
			if (a == 1) {
				if (rev) rear += b;
				else front += b;
			}
			else {
				if (rev) front += b;
				else rear += b;
			}
		}
	}

	if (rev) {
		reverse(rear.begin(), rear.end());
		reverse(S.begin(), S.end());
		cout << rear + S + front << endl;
	}
	else {
		reverse(front.begin(), front.end());
		cout << front + S + rear << endl;
	}
}

Measured memory_bytes: 1348
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, a, b, c = MAP()
C = {0: a, 1: b, 2: c}
S = []
for i in range(N):
    s = input()
    c1, c2 = s
    S.append((ord(c1)-65, ord(c2)-65))

ans = []
for i in range(N-1):
    cur1, cur2 = S[i]
    if C[cur1] == C[cur2] == 0:
        No()
        exit()
    elif C[cur1] == C[cur2] == 1 and C[3-cur1-cur2] == 0:
        if cur1 in S[i+1] and 3-cur1-cur2 in S[i+1]:
            ans.append(cur1)
            C[cur1] += 1
            C[cur2] -= 1
        else:
            ans.append(cur2)
            C[cur2] += 1
            C[cur1] -= 1
    elif C[cur1] <= C[cur2]:
        ans.append(cur1)
        C[cur1] += 1
        C[cur2] -= 1
    else:
        ans.append(cur2)
        C[cur2] += 1
        C[cur1] -= 1
cur1, cur2 = S[-1]
if C[cur1] == C[cur2] == 0:
    No()
    exit()
elif C[cur1] <= C[cur2]:
    ans.append(cur1)
    C[cur1] += 1
    C[cur2] -= 1
else:
    ans.append(cur2)
    C[cur2] += 1
    C[cur1] -= 1
Yes()
for i in range(N):
    print(chr(ans[i]+65))


Measured memory_bytes: 16792
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int a[maxn], b[maxn];
ll dp[5005];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int n, k;
    scanf("%d%d", &n, &k);

    int m = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (a[i] <= k) b[++m] = a[i];
    }
    dp[0] = 1;
    for (int i = 1; i <= m; i++) {
        for (int j = 5000; j >= b[i]; j--) {
            dp[j] = dp[j] + dp[j - b[i]];
        }
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = b[i]; j <= 5000; j++) {
            dp[j] -= dp[j - b[i]];
        }
        bool isok = true;
        for (int j = k - b[i]; j <= k - 1; j++) {
            if (dp[j]) {
                isok = false;
                break;
            }
        }
        if (isok) {
            ans++;
        }
        for (int j = 5000; j >= b[i]; j--) {
            dp[j] += dp[j - b[i]];
        }
    }
    printf("%d\n", ans);


    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();

		long answer = 0;
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				long b = f(N, i, j);
				long a = f(N, j, i);
				answer += a * b;
			}
		}

		System.out.println(answer);
	}

	private static long f(long N, long first, long last) {
		long a = 0;
		for (int i = 1; i <= N; i++) {
			if (i % 10 != last) continue;
			if (i < 10) {
				if (i != first) continue;
			} else if (i < 100) {
				if (i / 10 != first) continue;
			} else if (i < 1000) {
				if (i / 100 != first) continue;
			} else if (i < 10000) {
				if (i / 1000 != first) continue;
			} else if (i < 100000) {
				if (i / 10000 != first) continue;
			} else if (i < 1000000) {
				if (i / 100000 != first) continue;
			}
			a++;
		}
		return a;
	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll n, m, X, Y;
  cin >> n >> m >> X >> Y;
  vector<ll> x(n), y(m);
  cin >> x >> y;

  FOR(z, X+1, Y+1) {
    bool flag = true;
    REP(i, n) {
      if(x[i] >= z) {
        flag = false;
      }
    }
    REP(i, m) {
      if(y[i] < z) {
        flag = false;
      }
    }
    if(flag) {
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;

  return 0;
}


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

int main(){
  
  int N,i;
  int p = 0,w = 0,g = 0,y = 0;
  string S;
  cin >> N;
  cout << endl;
  
  for(i = 0;i < N;i++){
    cin >> S;
    
    if(S == "P"){
      p = 1;
    }
    
    if(S == "W"){
      w = 1;
    } 
    
    if(S == "G"){
      g = 1;
    }
    
    if(S == "Y"){
      y = 1;
    }
  }
  
  if(p + w + g + y == 4){
    cout << "Four" << endl;
  }else if(p + w + g + y == 3){
    cout << "Three" << endl;
  }
  
}

Measured memory_bytes: 256
d=input()
if d=='MON':
    print('6')
elif d=='TUE':
    print('5')
elif d=='WED':
    print('4')
elif d=='THU':
    print('3')
elif d=='FRI':
    print('2')
elif d=='SAT':
    print('1')
elif d=='SUN':
    print('7')



Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int a, b;

    for (int i=0; ; i++)
    {
        cin >> a >> b;

        if (a == 0 && b == 0)
            break;

        if (a > b)
            swap(a, b);

        cout << a << ' ' << b << endl;
    }

    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;



int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> f(n,vector<int>(10));
    rep(i,n) {
        rep(j,10) cin >> f[i][j];
    }
    vector<vector<ll>> p(n,vector<ll>(11));
    rep(i,n) {
        rep(j,11) cin >> p[i][j];
    }
    ll ans=-10e9;
    repr(bit,1,(1<<10)) {
        ll tans=0;
        rep(i,n) {
            int cnt=0;
            rep(j,10) {
                if ((bit & (1<<j))>0 && f[i][j]==1) {
                    ++cnt;
                }
            }
            tans+=p[i][cnt];
        }
        ans=(tans>ans)?tans:ans;
    }

    cout << ans  << endl;


    return 0;   
}


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

int main(){
    long long N, Q;
    scanf("%lld%lld", &N, &Q);

    vector<long long> A(N), AS(N + 2), S(N + 1), X((N - 1) / 2), a((N + 1) / 2);
    for(int i = 0; i < N; ++i){
        scanf("%lld", &A[i]);
        AS[i + 2] = A[i] + AS[i];
        S[i + 1] = A[i] + S[i];
    }

    for(int i = 1; i <= N / 2; ++i){
        a[i - 1] = S[N] - S[N - i] + AS[N - i * 2 + 1];
    }
    if(N & 1)*a.rbegin() = S[N] - S[N - (N + 1) / 2];
    for(int i = 1; i <= (N - 1) / 2; ++i){
        X[i - 1] = A[N - i - 1] + A[N - i * 2 - 1];
    }

    reverse(a.begin(), a.end());
    reverse(X.begin(), X.end());
    for(auto i : a) ++i; //It does not work without this line(I do not know why).

    for(long long i = 0, x = 0; i < Q; ++i){
        scanf("%lld", &x);
        auto tmp = min<long long>((N - 1) / 2, lower_bound(X.begin(), X.end(), x * 2) - X.begin());
        printf("%lld\n", a[tmp]);
    }
    return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int n, y;
    while (cin >> n, n) {
        cin >> y;
        int b, r, t, res;
        double mx = 0;
        for (int i=0; i<n; ++i) {
            cin >> b >> r >> t;
            if (t == 1) {
                double interest = 100.0 * (1 + y * r / 100.0);
                if (mx < interest) {
                    mx = interest;
                    res = b;
                }
            } else {
                double interest = 100.0 * pow(1 + r / 100.0, y);
                if (mx < interest) {
                    mx = interest;
                    res = b;
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#define DEBUG 0
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 8/10/2019, 9:02:11 PM
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using ll = long long;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return x ? MOD - x : 0; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a)
  {
    mint b{a};
    return *this *= b.power(MOD - 2);
  }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
class combination
{
public:
  vector<mint> inv, fact, factinv;
  static int MAX_SIZE;
  combination() : inv(MAX_SIZE), fact(MAX_SIZE), factinv(MAX_SIZE)
  {
    inv[1] = 1;
    for (auto i = 2; i < MAX_SIZE; i++)
    {
      inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for (auto i = 1; i < MAX_SIZE; i++)
    {
      fact[i] = mint(i) * fact[i - 1];
      factinv[i] = inv[i] * factinv[i - 1];
    }
  }
  mint operator()(int n, int k)
  {
    if (n >= 0 && k >= 0 && n - k >= 0)
    {
      return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
  }
};
int combination::MAX_SIZE = 3000010;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// constexpr double epsilon = 1e-10;
// constexpr ll infty = 1000000000000000LL;
// constexpr int dx[4] = {1, 0, -1, 0};
// constexpr int dy[4] = {0, 1, 0, -1};
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}

int main()
{
  ll K, X;
  cin >> K >> X;
  for (auto i = -K + 1; i < K; i++)
  {
    cout << X + i;
    if (i < K - 1)
    {
      cout << " ";
    }
    else
    {
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1e5 + 7;
const int mod = 1e9 + 7;
ll x[MAXN], y[MAXN];
inline ll add(ll x, ll y) {return (x + y) % mod;}
inline ll mul(ll x, ll y) {return (x * y) % mod;}
int main()
{
    int n, m; scanf("%d%d", &n, &m);
    ll sum = 0;
    for (int i = 1; i <= n; i++) 
    {
        scanf("%lld", &x[i]);
        sum = add(sum, mul(x[i] - x[i - 1], mul(i - 1, n - i + 1)));
    }
    ll ans = 0;
    for (int i = 1; i <= m; i++)
    {
        scanf("%lld", &y[i]);
        ans = add(ans, mul(sum, mul(y[i] - y[i - 1], mul(i - 1, m - i + 1))));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1792
// Last Change: 04/27/2019 22:19:25.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

long long gcd(long long a, long long b) {
  if (a == 0 and b == 0)
    return 0;
  a = abs(a);
  b = abs(b);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> dpL(N);
  vector<ll> dpR(N);

  for (auto &&e : A) {
    cin >> e;
  }

  dpL[0] = A[0];
  dpR[N - 1] = A[N - 1];
  for (ll i = 1; i < N; ++i) {
    dpL[i] = gcd(dpL[i - 1], A[i]);
    dpR[N - i - 1] = gcd(dpR[N - i], A[N - i - 1]);
  }

  ll ans = max(dpL[N - 2], dpR[1]);
  for (ll i = 1; i < N - 1; ++i) {
    ans = max(ans, gcd(dpL[i - 1], dpR[i + 1]));
  }

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 2560
N = int(input())
A = [int(a) for a in input().split()] + [0] * 2
X = [[-10**10] * (N+1) for _ in range(N+1)]
X[A[0]][A[1]] = 0
ans = 0
ma = 0
MA = [-10**10] * (N+1)
MA[A[0]] = MA[A[1]] = 0
for i in range(N):
    B = A[i*3+2:i*3+5]
    cnt = len(set(B))
    if cnt == 1:
        ans += 1
    elif cnt == 2:
        a1 = B[0]^B[1]^B[2]
        a2 = (sum(B) - a1) // 2
        X[a1], X[a1][a2], X[a2][a2] = [max(X[a2][j] + 1, X[j][a2] + 1, MA[j]) for j in range(N+1)], max(X[a1][a2], X[a2][a2] + 1, ma), max(ma, X[a2][a2], X[a1][a1] + 1)
        X[a2] = [max(X[a2][j], MA[j]) for j in range(N+1)]
        MA = [max(m, x1, x2) for m, x1, x2 in zip(MA, X[a1], X[a2])]
        MA[a1] = max(MA[a1], max(X[a1]), X[a2][a1])
        MA[a2] = max(MA[a2], X[a1][a2], X[a2][a2])
        ma = max(ma, MA[a1], MA[a2])
    else:
        a, b, c = B
        # X[a][b], X[a][c], X[b][c] = max(X[a][b], ma, X[c][c] + 1), max(X[a][c], ma, X[b][b] + 1), max(X[b][c], ma, X[a][a] + 1)
        X[a][b], X[a][c], X[b][c] = max(ma, X[c][c] + 1), max(ma, X[b][b] + 1), max(ma, X[a][a] + 1)
        X[a] = [max(x, m) for x, m in zip(X[a], MA)]
        X[b] = [max(x, m) for x, m in zip(X[b], MA)]
        X[c] = [max(x, m) for x, m in zip(X[c], MA)]
        MA[a] = max(MA[a], max(X[a]))
        MA[b] = max(MA[b], X[a][b], max(X[b]))
        MA[c] = max(MA[c], X[a][c], X[b][c], max(X[c]))
        MA = [max(m, xa, xb, xc) for m, xa, xb, xc in zip(MA, X[a], X[b], X[c])]
        ma = max(ma, MA[a], MA[b], MA[c])

print(ans + max(ma, max(max(x) for x in X)))

Measured memory_bytes: 171800
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int N; cin >>N;
  if (!(N%2)) cout <<N <<endl;
  else cout <<N*2 <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <cmath>
#include <iomanip>

using namespace std;


int main() {
    long long H;
    cin >> H;

    long long height = floor(log2(double(H))) + 1;

    long long answer=0;
    for(long long i=1; i<=height; i++){
        answer+=pow(2,i-1);
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
// 挿入ソート 2018/11/16

#include <iostream>
using namespace std;

void insertionSort(int *A, int n);

int main()
{
    int N, A[1000];

    cin >> N;
    for (int i=0; i<N; i++)
        cin >> A[i];

    // 入力直後の並び
    for (int i=0; i<N-1; i++)
        cout << A[i] << ' ';
    cout << A[N-1] << '\n';
    insertionSort(A, N);
    return 0;
}

void insertionSort(int *A, int N)
{
    int v, i, j;
    for (i=1; i<N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for (int k=0; k<N-1; k++)
            cout << A[k] << ' ';
        cout << A[N-1] << '\n';
    }
}


Measured memory_bytes: 3080