akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#include <time.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;



int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<ll> a(n);
    long i;
    ll max=-LINF;
    for(i=0; i<n; i++) {
        scanf("%lld", &a[i]);
        if(i>0) {
            max=MAX(max,a[i]-a[i-1]);
        }
    }
    for(i=0; i<n; i++) {
        a[i]-=(i+1)*max;
    }
    ll cnt0=max;
    ll cnt1=0;
    ll cnt2=0;
    for(i=1; i<n; i++) {
        ll tmp=a[i-1]-a[i];
        assert(tmp>=0);
        if(tmp%n) {
            printf("NO\n"); return 0;
        }
        cnt1+=(tmp/n);
        cnt2+=(n-i)*(tmp/n);
    }
    ll tmp=a[0]-cnt2;
    ll mm=(ll)n*(n+1)/2;
    if(tmp>=0 && tmp%mm==0) {
        if(cnt1>cnt0+tmp/mm) {
            printf("NO\n"); return 0;
        }
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 1024
import heapq

n, m = map(int, input().split(' '))
edges = [[] for _ in range(n)]
for _ in range(m):
  l, r, c = map(int, input().split(' '))
  edges[l - 1].append((r - 1, c))

dists = [None for _ in range(n)]
h = [(0, 0)]
for i in range(n):
  while len(h) > 0 and h[0][1] < i:
    heapq.heappop(h)
  if len(h) == 0:
    break
  dists[i] = h[0][0]
  for e in edges[i]:
    heapq.heappush(h, (e[1] + dists[i], e[0]))
print(-1 if dists[i] is None else dists[-1])

Measured memory_bytes: 34172
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll M, B;
bool init = false;
vector<pair<ll, ll>> MB = {{2147483647, 2147483634}, {2147483629, 2147483627}, {2147483587, 2147483583}, {2147483579, 2147483576}, {2147483563, 2147483550}, {2147483543, 2147483541}, {2147483497, 2147483492}, {2147483489, 2147483486}, {2147483477, 2147483475}};

//=============rolling_hash============================
vector<bool> rolling_hash(string a, string b) {
  if (!init) {
    init = true;
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rand10(0, 8);
    ll temp = rand10(mt);
    M = MB.at(temp).first;
    B = MB.at(temp).second;
  }
  ll al = a.size(), bl = b.size();
  vector<bool> res(al, false);
  ll t = 1;
  ll ah = 0, bh = 0;
  for (ll i = 0; i < bl; ++i) {
    ah = (ah * B + a.at(i)) % M;
    bh = (bh * B + b.at(i)) % M;
    t = (t * B) % M;
  }
  for (ll i = 0; i < al; ++i) {
    if (ah == bh) {
      res.at(i) = true;
    }
    ah = (ah * B + a.at((i + bl) % al)) % M;
    ah -= (a.at(i) * t) % M;
    if (ah < 0ll) {
      ah += M;
    }
    ah %= M;
  }
  return res;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  string s_ = s;
  while (s.size() < t.size()) {
    s += s_;
  }
  vector<bool> ps = rolling_hash(s, t);
  ll N = ps.size();
  ll ans = 0;
  vector<bool> used(N, false);
  for (ll i = 0; i < N; ++i) {
    if (ps.at(i) && !used.at(i)) {
      ll cnt = 1;
      ll now = i;
      while (true) {
        now = (now + t.size()) % N;
        if (used.at(now)) {
          cout << -1 << "\n";
          return 0;
        }
        if (!ps.at(now)) {
          break;
        }
        used.at(now) = true;
        cnt += 1;
      }
      now = i;
      while (true) {
        now -= t.size();
        if (now < 0) {
          now += N;
        }
        now %= N;
        if (used.at(now)) {
          cout << -1 << "\n";
          return 0;
        }
        if (!ps.at(now)) {
          break;
        }
        used.at(now) = true;
        cnt += 1;
      }
      ans = max(ans, cnt);
    }
  }
  cout << ans << "\n";
  // for (ll i = 0; i < ps.size(); ++i) {
  //   if (ps.at(i)) {
  //     cout << '1';
  //   }
  //   else {
  //     cout << '0';
  //   }
  // }
  // cout << "\n";
}


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

int main() {
  int n,x,count=1,d=0,j=0;
  cin>>n>>x;
  vector<int> v(n);
  cin>>v.at(0);
  for(int i=1;i<n;i++){
    cin>>v.at(i);
    v.at(i)+=v.at(i-1);
  }
  for(int i=0;i<n;i++){
     if(v.at(i)<=x){
       count++;
     }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
#define NIL -1
using ll = long long;
const ll MOD = 1000000007;
#define REP(i,n) for (ll i=0; i < (n); ++i)
#define FOR(i,a,b) for (ll i=(a); i < (b); ++i)
using namespace std;

int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

  int n;
  cin >> n;

  auto is_ok = [](const string& str){
    REP(i,4) {
      string s = str;
      if (i > 0) swap(s[i],s[i-1]);
      REP(j,2) {
        if(s.substr(j,3) == "AGC") return false;
      }
    }
    return true;
  };

  // i文字で、最後の3文字がsであるの時の条件を満たす文字列数
  vector<map<string, int>> dp(n+1);
  const string nexts = "ACGT";
  dp[0]["TTT"] = 1;
  for(int i=0; i<n; i++){
    for (const auto& prev: dp[i]) {
      REP(j,4) {
        const string str = prev.fi + nexts[j];
        if (is_ok(str)) {
          dp[i+1][str.substr(1,3)] += prev.se;
          dp[i+1][str.substr(1,3)] %= MOD;
        }
      }
    }
  }

  int ans = 0;
  for(const auto& x: dp[n]) {
    ans += x.se;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define first fi
#define second se
#define sz(x) (int)x.size()
const int inf = 0x3f3f3f3f;
const int N = 200005;
const int mod = 1e9+7;

int x;

int main() {
    scanf("%d", &x);
    int sum = 0, Max = 0;
    for (int i = 1; ; i++) {
        if ((i&(-i)) == i) {
            sum += i;
            Max = max(Max, i);
        }
        int tmp = x - i * (i + 1) / 2 + sum;
       // printf("%d %d\n", i, tmp);
        for (int j = 30; j >= 0; j--) {
            if (tmp>>j&1) {
                if (i >= (1<<j)) {
                    printf("%d\n", i);
                    return 0;
                }
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		// get a string
		String s = sc.next();
	
		if (s.isEmpty()) {
			System.out.println("No");
			return;
		}
		
		if (s.matches("(.*)C(.*)F(.*)")) {
			System.out.println("Yes");
		}else System.out.println("No");
	
	}

}


Measured memory_bytes: 9684
#include <iostream>

using namespace std;

int main() {

	int n, x;
	int count;

	while (cin >> n >> x) {

		//0 0?????¨?????????
		if (n == 0 && x == 0) {
			break;
		}

		count = 0;

		//
		for (int i = 1; i <= n; i++) {
			for (int j = i+1; j <= n; j++) {
				for (int k = j+1; k <= n; k++) {
					if (i + j + k == x) {
						count++;
					}
				}
			}
		}

		cout << count << endl;
		
	}

	return 0;
}

Measured memory_bytes: 3036
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] number = line.split(" ");
        int n = Integer.parseInt(number[0]);
        int m = Integer.parseInt(number[1]);
        int k = Integer.parseInt(number[2]);
        if(k >= n && k <= m){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    ll N; cin >> N;
    string S; cin >> S;
    unordered_map<char, int> cnt;
    REP(i,N){
        cnt[S[i]] += 1;
    }
    ll ans = 1;
    for(auto pair:cnt){
        ans *= (pair.second + 1);
        ans = ans % (1000000000 + 7);
        // cout << pair.second << endl;
    }
    cout << (ans - 1);
    return 0;
}

Measured memory_bytes: 512
n, m = map(int, input().split())
cs = []
cd = {}
ps = {}
for _ in range(m):
  p, y = map(int, input().split())
  cs.append([p, y])
  if p in ps:
    ps[p].append(y)
  else:
    ps[p] = [y]
    
for p in ps:
  v = sorted(ps[p])
  for i, y in enumerate(v):
    cd[y] = i + 1
[print('{:06}{:06}'.format(c[0], cd[c[1]])) for c in cs]

 
  
  


Measured memory_bytes: 48688
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 100005
#define MOD 1000000007
#define LL long long
int x[N],n,m;
bool vis[N];
struct node
{
	LL a[3][3];
}A,C,a,b,c,tmp;
int f[3],g[3];
node Mul(node res,node X,node Y)
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			tmp.a[i][j]=0;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
				tmp.a[i][j]=(tmp.a[i][j]+X.a[i][k]*Y.a[k][j]%MOD)%MOD;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			res.a[i][j]=tmp.a[i][j];
	return res;
}
void Pow(int X)
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			c.a[i][j]=C.a[i][j];
	while(X)
	{
		if(X&1) a=Mul(a,a,c);
		c=Mul(c,c,c);
		X>>=1;
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",&x[i]);
	memset(A.a,0,sizeof(A.a));
	memset(C.a,0,sizeof(C.a));
	A.a[0][0]=A.a[1][1]=A.a[2][2]=A.a[1][2]=A.a[0][2]=1;
	A.a[0][1]=2;
	C.a[0][2]=C.a[1][0]=C.a[1][1]=C.a[1][2]=C.a[2][0]=C.a[2][2]=1;
	C.a[0][0]=C.a[0][1]=2;
	f[0]=1;
	x[++m]=n;
	for(int l=1,pos=0;l<=m;l++)
	{
		int k=x[l]-pos-1;
		memset(b.a,0,sizeof(b.a));
		memset(a.a,0,sizeof(a.a));
		for(int i=0;i<3;i++)
			a.a[i][i]=1;
		if(k) Pow(k);
		b=Mul(b,a,A);
		for(int i=0;i<3;i++)
		{
			g[i]=0;
			for(int j=0;j<3;j++)
				g[i]=(g[i]+f[j]*b.a[j][i]%MOD)%MOD;
		}
		for(int i=0;i<3;i++)
			f[i]=g[i];
		pos=x[l];
	}
	printf("%d\n",f[2]);
}


Measured memory_bytes: 512
A, B, C = map(int, input().split())

if any(map(lambda x: x%2 == 1, (A, B, C))):
    print(0)
elif A == B == C:
    print(-1)
else:
    ans = 0
    cookie = A + B + C
    while all(map(lambda x: x%2 == 0, (A, B, C))):
        A = (cookie - A) / 2
        B = (cookie - B) / 2
        C = (cookie - C) / 2
        ans += 1
    print(ans)


Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int                 long long   
#define double              long double
#define endl                "\n"
#define pb                  push_back
#define PI                  3.1415926535897932384626433832795l
#define F                   first
#define S                   second
#define mp                  make_pair
#define f(i,n)              for(int i=0;i<n;++i)
#define loop(i,a,b)         for (int i=a ; i<b ;++i)
#define fastio              ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define gcd(a,b)            __gcd((a),(b))
#define fill(a,value)       memset(a,value,sizeof(a));
#define minn(v)             *min_element(v.begin(), v.end());
#define maxx(v)             *max_element(v.begin(), v.end());
#define print(x)            cout<<(x)<<endl;
#define sum(v)+x            accumulate(v.begin(), v.end(),x);
typedef pair<int,int> pii;  
typedef vector<int> vi;

signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    string s;
    cin>>s;
    int ans=0;
    int cur=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='R')cur++;
        else
        {
            ans=max(ans,cur);
            cur=0;
        }
    }
    ans=max(ans,cur);
    print(ans)
    
    
    return 0;
}

Measured memory_bytes: 3648
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int

#define M_DEBUG 1
#define PI 3.141592653589793
#define MOD 100000007

#define M 1000000000

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

int main(void){
    string ss = "abcdefghijklmnopqrstuvwxyz";
    char c;
    cin >> c;
    for (int i = 0; i < ss.size(); ++i) {
        if (ss[i] == c) {
            cout << ss[i + 1] << endl;
            break;
        }

    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

const int MAX_N = (3e+5)+10;
vec nCm(MAX_N+1,0);
vec fact(MAX_N+1,0),fact_inv(MAX_N+1,0);

ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}
void makefact(ll n){//MODは素数かつnより大きい
    ll ans = 1;
    fact.at(0) = ans;
    fact_inv.at(0) = ans;
    reps(i,1,n+1){
        (ans *= i)%=MOD;
        fact.at(i) = ans;
        fact_inv.at(i) = fastpow(ans,MOD-2);
    }
    return;
}
void makenCm(ll n){
    rep(i,n+1){
        ll ans = fact.at(n);
        (((ans*=fact_inv.at(n-i))%=MOD)*=fact_inv.at(i))%=MOD;
        nCm.at(i) = ans;
    }
    return;
}


int main() {
    cin>>N>>A>>B>>K;
    makefact(N+10);
    makenCm(N);
    ll ans = 0;
    rep(i,N+1){
        if((K >= A*i) && ((K - A*i)%B == 0) && ((K - A*i)/B <= N)) (ans += (nCm.at(i) * nCm.at((K - A*i)/B))%MOD)%=MOD;
    }
    cout<<ans<<endl;
}

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

string s;
int D;
long long dp[10010][110][2] , mod = 1e9 + 7;

long long get(int i = 0 , int sum = 0 , bool flag = 0)
{
    if(i == s.size())return (sum == 0);
    long long &ret = dp[i][sum][flag];
    if(~ret)    return ret;

    ret = 0;
    for(int j = 0 ; j <= (flag ? 9 : s[i] - '0') ; j++)
        ret = (ret + get(i+1,(sum + j)%D, flag | (j < s[i] - '0')))%mod;

    return ret;
}
int main()
{
    cin.tie();  ios::sync_with_stdio(false);
    cin >> s >> D;
    memset(dp,-1,sizeof dp);
    cout << (get() +mod - 1)%mod<< '\n';
    return 0;
}


Measured memory_bytes: 18560
#include <iostream>
using namespace std;
int main (void){

   int a,b;
       cin >> a>>b;
 
   if(a>b) 
    cout<<"a > b"<<endl;
   
   else if(a<b) 
    cout<<"a < b"<<endl;

   else cout<<"a == b"<<endl;
 
 
return 0;
 
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

int main() 
{
    fastio();

    string a;
    cin>>a;
    int rem = 0;
    for( auto x : a )
    {
        rem = mod( rem + x-'0' , 9 );
    }
    puts( rem == 0 ? "Yes" : "No" );

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int mod = 998244353;

long long pow_mod(long long a, long long b) {
	long long ret = 1;
	while (b > 0) {
		ret = ret * a % mod;
		b--;
	}

	return ret;
}

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

	vector<int> d(n, 0);
	int maxi = 0;
	for (int i = 0; i < n; i++) {
		cin >> d[i];
		maxi = max(maxi, d[i]);
	}

	vector<int> n_dists(maxi + 1, 0);
	for (auto x: d) {
		n_dists[x]++;
	}

	if (d[0] != 0 || n_dists[0] != 1) {
		cout << 0 << endl;
		return 0;
	}


	long long ans = 1;
	for (int i = 1; i < n_dists.size(); i++) {
		if (n_dists[i] == 0) {
			ans = 0;
		} else {
			long long c = pow_mod(n_dists[i-1], n_dists[i]);
			// printf("i %d: n_dists %d, c %lld\n", i, n_dists[i], c);
			ans = ans * c % mod;
		}
	}

	cout << ans << endl;
	return 0;
}


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

int main(){
  int n,m,s,a;
  // while(cin>>n,n)
  // int i,j;
  // i=1;
  // j=++i;
  // cout << i<<j;
  // i=1;
  // j=i++;
  // cout << i<<j;
  // while(++i,i<=10)
  //   cout<<i<<endl;
  while(cin>>n,n){
    cin>>a;
    m=s=a;n--;
    while(n--){
      cin>>a;
      if(s<0)s=a;
      else s+=a;
      m=max(s,m);
    }
    cout << m<<endl;
  }
  return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))//数组(结构体)清零 
#define ll long long
//int A(int a,int b){if(a<b||a<1||b<0)return 0;int k=1;while(b--){k*=a--;}return k;}//数学中的Aab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
//int C(int a,int b){if(a<b||a<1||b<0)return 0;b=min(a-b,b);int k=A(a,b),t=1;while(--b)k/=++t;return k;}//数学中的Cab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
//int HW(char*HWa,int HWl,int HWr){if(HWr<HWl)swap(HWl,HWr);for(int i=0;i<(HWr-HWl)/2+1;i++)if(HWa[HWl+i]!=HWa[HWr-i])return 0;return 1;}//传递字符串名,判断区间l r,如果是回文字符串就返回1,否则返回0 
//int SS(int a){if(a>4&&((a-1)%6)&&((a+1)%6))return 0;for(int i=2;i<=sqrt(a);i++)if(a%i==0)return 0;return 1;}//判断一个数是不是质数，是1 否0；请确保a>1; 
/*记得如果改int为long long,就把printf与scanf中相应的%d也改成%lld*/
int d[2005]={0};
int main()
{
	int i,j,x,y,n,dis;
	cin>>n>>x>>y;
	for(i=1;i<n;i++)
		for(j=i+1;j<=n;j++)
		{
			dis=min(j-i,abs(i-x)+1+abs(j-y));
			d[dis]++;
		}
	for(i=1;i<n;i++)
		printf("%d\n",d[i]);
	return 0;
}

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

using namespace std;

const int Nmax = 1e5 + 5;

int n, m;
vector<int> v[Nmax];

int solve(vector<int> &a, vector<int> &b)
{
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int leftA, leftB, matA = 0, matB = 0;
    int i;

    for(i=0; i<a.size(); ++i)
        if(i+1<a.size() && a[i] == a[i+1])
        {
            a[i] = a[i+1] = -1;
            ++matA;
        }

     for(i=0; i<b.size(); ++i)
        if(i+1<b.size() && b[i] == b[i+1])
        {
            b[i] = b[i+1] = -1;
            ++matB;
        }

    leftA = ((int)a.size() - 2*matA);
    leftB = ((int)b.size() - 2*matB);


    int ans;

    if(leftA > leftB)
        swap(leftA, leftB), swap(matA, matB);

    ans = leftA;
    leftB -= leftA;

    while(matA>0 && leftB>=2)
        leftB-=2, ans+=2, matA--;

    ans += matA;
    ans += matB;

    return ans;
}

int main()
{
//    freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);


    cin >> n >> m;
    int i;
    for(i=1; i<=n; ++i)
    {
        int x;
        cin >> x;
        v[x%m].push_back(x);
    }

    int ans = 0;

    for(i=0; i<m; ++i)
        if(i == 0 || i==m-i)
            ans += (int)v[i].size() / 2;
        else
            if(i < m-i)
                ans += solve(v[i], v[m-i]);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 5760
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int n,a[105],mx,ans,res;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i],mx=max(mx,a[i]);
	ans=inf;
	for(int i=1;i<=mx;i++)
	{
		res=0;
		for(int j=1;j<=n;j++)
			res+=(i-a[j])*(i-a[j]);
		ans=min(ans,res);
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

int main(){

    int h,w;
    cin >> h;
    cin >> w;

    char m[h][w];
    for(int i=0;i<h;i++){
        string f;
        cin >> f;
        for(int l=0;l<w;l++){
            m[i][l] = f[l];
        }
    }

  
	int s[h][w];
    for(int i=0;i<h;i++){
        for(int l=0;l<w;l++){
            if(m[i][l] != '#'){
            int cnt = 0;
            if(i != 0 && m[i-1][l] == '#') cnt++;
            if(i != h-1 && m[i+1][l] == '#') cnt++;
            if(l != 0 && m[i][l-1] == '#') cnt++;
            if(l != w-1 && m[i][l+1] == '#') cnt++;
            if((i != 0 && l != 0 )&& m[i-1][l-1] == '#') cnt++;
            if((i != h-1 && l != 0 )&& m[i+1][l-1] == '#') cnt++;
            if((i != 0 && l != w-1 )&& m[i-1][l+1] == '#') cnt++;
            if((i != h-1 && l != w-1 )&& m[i+1][l+1] == '#') cnt++;
            s[i][l] = cnt;
            }
        }
    }
  
  	for(int i=0;i<h;i++){
        for(int l=0;l<w;l++){
        	if(m[i][l] == '#') {cout << '#';}
          	else cout << s[i][l];
          	
            if(l == w-1) cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
main(){
  int n,k,s[100000],b,i,j,ss[100000],jud;
  while(1){
    jud=1;
    scanf("%d%d",&n,&k);
    if(n == 0 && k == 0) break;
    for(i=0;i<k;i++){
      scanf("%d",&s[i]);
      ss[i]=0;
    }
    for(i=0;i<n;i++){
      for(j=0;j<k;j++){
	scanf("%d",&b);
	ss[j]+=b;
      }
    }

    for(i=0;i<k;i++){
      if(ss[i] > s[i]){
	jud=0;
	break;
      }
    }
    if(jud == 1) printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <fstream>
#include <cassert>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979
#define FILL(a,v) memset(a,v,sizeof(a))

using namespace std;


typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PII;

bool compatible(const string &a1, const string &a2) {
    int sz = min(a1.length(), a2.length());
    REP(i,sz) {
        if (a1[i] != a2[i])
            return false;
    }
    return true;
}

map<string, map<string, Long>> dp[40][40][20];

string s;
int n;

Long solve(string s1, string s2, int l, int r, int t) {
    if (dp[l][r][t].count(s1) && dp[l][r][t][s1].count(s2))
        return dp[l][r][t][s1][s2];

    if (!compatible(s1, s2))
        return false;
    if (l >= r) {
//        cout << l << " " << r << " " << s1 << " " << t << endl;
        return s1 == s2 && (s1.length() + t == n);
    }

    Long res = 0, tmp;

    // mingled
    FOR(i,l,r)
        FOR(j,i+1,r)
        if (s[i] == s[j])
        {
            string ns1 = s1;
            FOR(u, l, i)
                ns1 += s[u];
            string ns2 = s2;
            RFOR(u, r, j+1)
                ns2 += s[u];

            tmp = solve(ns1, ns2, i+1, j, t+1);
            res += tmp;
            if (t == 0 && tmp != 0) {
//                cout << i << " " << j << " " << ns1 << " " << ns2 << " " << tmp << endl;
            }
    }

    // split exactly
    FOR(i,l+1,r)
        if (s[i] == s[i-1]) {
        string ns1 = s1;
        FOR(u, l, i)
            ns1 += s[u];
        string ns2 = s2;
        RFOR(u, r, i)
            ns2 += s[u];

        res += solve(ns1, ns2, n, 0, t);
    }

    // to left
    string ns1 = s1;
    FOR(u,l,r)
        ns1 += s[u];
    res += solve(ns1, s2, n, 0, t);

    // to right
    string ns2 = s2;
    RFOR(u,r,l)
        ns2 += s[u];
    res += solve(s1, ns2, n, 0, t);

    dp[l][r][t][s1][s2] = res;
    return res;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> s;
    cout << solve("", "", 0, 2*n, 0) << endl;

    return 0;
}

Measured memory_bytes: 14848
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int H = I[0], W = I[1], K = I[2] - 1;
		if (W == 1) { WriteLine(1); return; }
		var A = new long[W, W];
		for (var i = 0; i < 1 << (W - 1); i++)
		{
			var flag = true;
			for (var j = 0; j < W - 1; j++) flag &= (i & (3 << j)) != (3 << j);
			if (!flag) continue;
			for (var j = 0; j < W - 1; j++)
				if ((i & (1 << j)) == 0) A[j, j]++;
				else
				{
					A[j, j + 1]++;
					A[j + 1, j]++;
					j++;
				}
			if ((i & (1 << (W - 2))) == 0) A[W - 1, W - 1]++;
		}
		var M = new Matrix(A);
		M = M.Pow((ulong)H, MOD);
		WriteLine(M[0, K]);
	}
}
class Matrix
{
	public int Row { get; protected set; }
	public int Column { get; protected set; }
	private long[,] a;
	public long this[int r, int c] { get { return a[r, c]; } set { a[r, c] = value; } }
	public Matrix(int r, int c) { Row = r; Column = c; a = new long[r, c]; }
	public Matrix(long[,] components) : this(components.GetLength(0), components.GetLength(1), (i, j) => components[i, j]) { }
	public Matrix(int r, int c, Func<int, int, long> components) : this(r, c) { for (var i = 0; i < r; i++) for (var j = 0; j < c; j++) this.a[i, j] = components(i, j); }
	public static Matrix operator +(Matrix p) => new Matrix(p.a);
	public static Matrix operator %(Matrix p, long mod) => new Matrix(p.Row, p.Column, (i, j) => p.a[i, j] % mod);
	public static Matrix operator *(Matrix p, Matrix q)
		=> new Matrix(p.Row, q.Column, (i, j) => { var sum = 0L; for (var k = 0; k < p.Column; k++) sum = (sum + p.a[i, k] * q.a[k, j]); return sum; });
	public static Matrix One(int size) => new Matrix(size, size, (i, j) => i == j ? 1 : 0);
	public Matrix Pow(ulong n, long mod)
	{
		var p = One(Row);
		var x = this % mod;
		while (n > 0)
		{
			if ((n & 1) == 1) p = (p * x) % mod;
			n >>= 1;
			x = (x * x) % mod;
		}
		return p % mod;
	}
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//int a[55],b[55];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	int a = n/500;
	int b = (n%500)/5;
	cout << 1000*a + 5*b << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#define MAX 2000001
#define VMAX 10000

int main()
{
	unsigned short* A, * B;
	int C[VMAX + 1];
	int n, i, j;
	scanf("%d", &n);

	A = (unsigned short*)malloc(sizeof(short) * n+1);
	B= (unsigned short*)malloc(sizeof(short) * n+1);

	for (i = 0; i <= VMAX; i++)
		C[i] = 0;

	for (i = 0; i < n; i++)
	{
		scanf("%hu", &A[i+1]);
		C[A[i+1]]++;
	}

	for (i = 1; i <= VMAX; i++)
		C[i] = C[i] + C[i - 1];
	
	for (i = 1; i <= n; i++)
	{
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}

	for (i = 1; i <= n; i++)
	{
		if (i > 1)
			printf(" ");
		printf("%d", B[i]);
	}
	putchar(10);
	return 0;
}



Measured memory_bytes: 10440
#include <bits/stdc++.h>
#define pb push_back
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007

#define par pair<int, int>
#define maxn 505

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

ll N,a,ex=1;
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    for(int i=1;i<=N;i++){
        cin >> a ;
        if(a == ex)
            ex++;
    }
    if(ex==1)
        cout << "-1\n";
    else
        cout << N - ex+1;


}


Measured memory_bytes: 256
s=gets.chop
gets.to_i.times do
c,a,b,p=gets.split
a=a.to_i
b=b.to_i
case c
when 'print'
puts s[a..b]
when 'reverse'
s[a..b]=s[a..b].reverse
when 'replace'
s[a..b]=p
end
end


Measured memory_bytes: 6936
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int n, k; cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  sort(ALL(h));

  int ans = INF;
  rep(i, n - k + 1){
    ans = min(ans, h[i + k - 1] - h[i]);
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
    int N;
    std::string S;
    std::cin >> N >> S;

    int64_t cnt_r = 0, cnt_g = 0, cnt_b = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'R') {
            ++cnt_r;
        } else if (S[i] == 'G') {
            ++cnt_g;
        } else {
            ++cnt_b;
        }
    }

    int64_t p = cnt_r * cnt_g * cnt_b;
    for (int i = 0; i < N - 2; ++i) {
        for (int j = i + 1; j < N - 1; ++j) {
            const int k = 2 * j - i;
            if (N <= k) {
                continue;
            }        

            if ((S[i] != S[j]) && (S[j] != S[k]) && (S[k] != S[i])) {
                --p;
            }
        }
    }

    std::cout << p << std::endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
const int64_t INF=9999999999999999;

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

Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    auto cmp = [](const pair<int, int> &a, const pair<int, int> &b) { return a.second > b.second; };
    int s1, s2;
    pair<int, int> ds[5];
    string str = "ABCDE";

    for (;;) {
        scanf("%d %d", &s1, &s2);
        if (s1 == 0 && s2 == 0) break;
        for (int i = 0; i < 5; i++) ds[i] = {i, 0};
        ds[0].second = s1+s2;
        for (int i = 1; i < 5; i++) { scanf("%d %d", &s1, &s2); ds[i].second = s1+s2; }
        sort(ds, ds+5, cmp);
        printf("%c %d\n", str[ds[0].first], ds[0].second);
    }

    return 0;
}



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

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;
static long long INF = (1LL<<62);
using LLPair = pair<LL, LL>;

const LL MAXT = 100000;

int contain(vector<pair<LL, LL>> &v, LL t){
	if(v.size() == 0) return 0;

	int ret = 0;
	pair<LL, LL> p = make_pair(t, t);
	LL l1 = -1, r1 = -1, l0 = -1, r0 = -1;
	auto itr = lower_bound(v.begin(), v.end(), p);
	if(itr == v.end()){
		itr--;
	}
	l1 = itr->first;
	r1 = itr->second;
	if(t >= l1 && t <= r1){
		ret = 1;
	}
	if(t < l1){
		if(itr == v.begin()){
			ret = 0;
		}
		else{
			itr--;
			l0 = itr->first;
			r0 = itr->second;
			if(l0 <= t && t <= r0){
				ret = 1;
			}
			else{
				ret = 0;
			}
		}
	}
	return ret;
}

int main(int argc, char* argv[]){

	LL N, C; cin >> N >> C;
	LL S = MAXT, T = 0;
	vector<vector<pair<LL, LL>>> V(C);
	map<LL, int> CP; 
	for(int i=0; i<N; i++){
		LL s, t, c; cin >> s >> t >> c;
		c--;
		V[c].push_back(make_pair(s, t));
		if(S > s) S = s;
		if(T < t) T = t;
		if(CP.count(s) == 0) CP[s] = 1;
		if(CP.count(t) == 0) CP[t] = 1;
	}
	for(int c=0; c<C; c++){
		sort(V[c].begin(), V[c].end());
	}
	int ans = 0;
	for(auto itr = CP.begin(); itr != CP.end(); itr++){
		LL t = itr->first;
		int rec = 0;
		for(int c=0; c<C; c++){
			int r  = contain(V[c], t);
			rec += r;
		}
		if(ans < rec) ans = rec;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 11172
import sys, itertools, copy
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    H, W, K = LI()
    c = [[int(i) for i in S()] for _ in range(H)]

    ans = 0
    for i, j in itertools.product(range(H), range(W)):
        c_tmp = copy.deepcopy(c)
        c_tmp[i][j] = 0
        score = 0
        chain_cnt = 0
        while True:
            # 落下処理
            # その石がどれだけ落下するかの算出
            drop = [[0]*W for _ in range(H)]
            for k in range(W):
                for l in range(H-1):
                    drop[H-l-2][k] = drop[H-l-1][k] + (1 if c_tmp[H-l-1][k]==0 else 0)
            # print('drop')
            # for i in drop:
            #     print(i)
            
            # 落下先にコピー
            for k in range(W):
                for l in range(H):
                    if drop[H-l-1][k]!=0:
                        c_tmp[H-l-1+drop[H-l-1][k]][k] = c_tmp[H-l-1][k]
                        c_tmp[H-l-1][k] = 0
            # print('dropped s')
            # for i in c_tmp:
            #     print(i)

            # 消滅判定
            num_sum = 0
            for k in range(H):
                prev = 0
                cnt = 1
                for l in range(W):
                    if c_tmp[k][l]==prev:
                        cnt += 1
                    else:
                        if cnt>=K:
                            num_sum += prev*cnt
                            for m in range(cnt):
                                c_tmp[k][l-cnt+m] = 0
                        prev = c_tmp[k][l]
                        cnt = 1
                if cnt>=K:
                    num_sum += prev*cnt
                    for m in range(cnt):
                        c_tmp[k][l+1-cnt+m] = 0
            # print('s')
            # for i in s:
            #     print(i)
            if num_sum==0:
                break
            score += (2**chain_cnt) * num_sum
            chain_cnt += 1
        ans = max(score, ans)

    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 57180
#include<iostream>

using namespace std;

int main()
{
	int N;
    string S;
	cin >> N >> S;
  	if( N>=S.length() )
        cout << S;
    else
    {
        for(int i = 0 ; i < N ; i++ )
        	cout << S[i];
        cout <<"...";
    }
    return 0;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define Fd(i,a,b) for(ll i=a;i>=b;i--)
using namespace std;
const int N=100005;

ll A[N],B[N],C[N];
ll resB[N];

 int main()
 {
	int n;
	scanf("%d",&n);

	F(i,1,n) scanf("%lld",&A[i]);
	F(i,1,n) scanf("%lld",&B[i]);
	F(i,1,n) scanf("%lld",&C[i]);

	sort(A+1,A+n+1);
	sort(B+1,B+1+n);
	sort(C+1,C+1+n);

	int range=0;
	F(i,1,n)
	{
		while(range<n&&A[range+1]<B[i]) range++;
		resB[i]=range;
	}

	range=0;
	ll sum=0;
	ll result=0;
	F(i,1,n)
	{
		while(range<n&&B[range+1]<C[i]) range++, sum+=resB[range];
		result+=sum;
	}

	printf("%lld\n",result);
 }


Measured memory_bytes: 3328
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
A = [1 for _ in range(10001)]
for i in range(2,10001):
    A[i] = (i*A[i-1])%p
B = [1 for _ in range(10001)]
B[10000] = pow(A[10000],p-2)
for i in range(9999,1,-1):
    B[i] = ((i+1)*B[i+1])%p
def f(n,k):
    if k>n:
        return 0
    return (A[n]*B[k]*B[n-k])%p
S = int(input())
n = S//3
ans = 0
for i in range(n,0,-1):
    k = S-3*i
    ans = (ans+f(k+i-1,i-1))%p
print(ans)

Measured memory_bytes: 69424
#include <bits/stdc++.h>
#define ll int
using namespace std;

int main() {
	ll n;
	cin>>n;
	vector<ll>v(n);
	for(ll i=0;i<n;i++)
	{
		cin>>v[i];
	}
	unordered_map<ll,ll>u;
	for(ll i=0;i<n;i++)
	{
		u[v[i]]++;
	}
	ll ans=0;
	unordered_map<ll,ll>::iterator it;
	for(it=u.begin();it!=u.end();it++)
	{
		if(it->first!=it->second)
		{
			if(it->first>it->second)
				ans+=it->second;
			else
				ans+=it->second-it->first;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4644
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;


int main(){
    int a;
    cin >> a;
    int ans = a + a * a + a*a*a;
    cout <<ans <<endl;
}


Measured memory_bytes: 3616
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

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

        // 入力
        int n = sc.nextInt();
        //String s = sc.next();

        // 処理
        int[] buka = new int[n];
        for(int i = 2; i <= n; i++){
            int a = sc.nextInt();
            buka[a-1] += 1;
        }

        for(int i = 0; i < n; i++){
            System.out.println(buka[i]);
        }

        // 出力
        //System.out.println(out);
    }
}

Measured memory_bytes: 62288
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

double ternary_search_downwards(double lb, double ub, const function<double(double)> &f){
  double t1,t2;
  REP(i,300){
    t1 = lb+(ub-lb)/3;
    t2 = lb+(ub-lb)/3*2;
    
    if(f(t1) < f(t2)){
      ub = t2;
    }else{
      lb = t1;
    }
  }
 
  return lb;
}



const double MIN = -1e18;
const double MAX = 1e18;


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

  int N;
  while(cin >> N){
    vector<double> x(N), y(N);
    vector<char> d(N);

    REP(i,N){
      cin >> x[i] >> y[i] >> d[i];
    }
    
    auto funcx =
      [&](double t){
	double xmin = MAX, xmax = MIN;

	REP(i,N){
	  if(d[i] == 'R'){
	    chmin(xmin, x[i]+t);
	    chmax(xmax, x[i]+t);
	  }else if(d[i] == 'L'){
	    chmin(xmin, x[i]-t);
	    chmax(xmax, x[i]-t);
	  }else{
	    chmin(xmin, x[i]);
	    chmax(xmax, x[i]);
	  }
	}

	return xmax-xmin;
      };

    auto funcy =
      [&](double t){
	double ymin = MAX, ymax = MIN;

	REP(i,N){
	  if(d[i] == 'U'){
	    chmin(ymin, y[i]+t);
	    chmax(ymax, y[i]+t);
	  }else if(d[i] == 'D'){
	    chmin(ymin, y[i]-t);
	    chmax(ymax, y[i]-t);
	  }else{
	    chmin(ymin, y[i]);
	    chmax(ymax, y[i]);
	  }
	}

	return ymax-ymin;
      };

    auto check =
      [&](double t){
	double ret = funcx(t) * funcy(t);
	return ret;
      };


    double a = ternary_search_downwards(0,2e8,[&](double t){return check(t);});    
    double ans = check(a);
    
    cout << fixed << setprecision(15) << ans << endl;
  }
  
  return 0;
}


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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

bool checkpal(string s)
{
    int n = s.size();
    f1(i,0,n/2)
    {
        if(s[i] != s[(n-1)-i])
        return false;
    }
    return true;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin>>s;

    int n = s.size();

    
    string temp1,temp2;
    f1(i,0,n/2)
    {
        temp1.push_back(s[i]);
    }
    f2(i,n-1,(n+1)/2)
    {
        temp2.push_back(s[i]);
    }
    // cout<< temp1<<gp<<temp2<<endl;
    if( checkpal(temp1) == true && temp1 == temp2 )
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
long long N, K, A[1<<18];
 
int main(){
  cin >> N >> K;
  for(int i = 1; i <= N; i++){
    cin >> A[i];
  }
  for(int i = K+1; i <=N; i++){
    if(A[i-K] < A[i]) cout << "Yes" << '\n';
    else cout << "No" << '\n';
  }
  return 0;
}

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

using namespace std;
const int nax = 2e5 + 5;
vector<int> adj[nax];
int visit[nax];
int mp[nax];

void dfs(int n) {
  if(visit[n])
    return;
  visit[n] = 1;
  for(int x: adj[n]) {
    mp[x] += mp[n];
  //  cout << "x: " << x+1 << " val: " << mp[x] << "\n";
    dfs(x);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q; cin >> n >> q;
  for(int i=0; i<n-1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    adj[a].push_back(b);
 //   adj[b].push_back(a);
  }
  for(int i=0; i<q; ++i) {
    int p, x; cin >> p >> x;
    mp[--p] += x;
  }
  dfs(0);
  for(int i=0; i<n; ++i) {
    cout << mp[i] << " ";
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 21120
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 60;                        
string S;
int64 k, dp[2000][2000], dp2[2000][2000];

inline void merge(int64& a, int64 b)
{
  a = min(a + b, INF);
}

int main()
{
  cin >> S;
  cin >> k; --k;

  for(int i = 0; i < S.size(); i++) {
    dp[i][i] = 1, dp2[i][i] = 1;
  }
  for(int i = 0; i < S.size() - 1; i++) {
    if(S[i] == S[i + 1]) dp[i][i + 1] = 2, dp2[i][i + 1] = 1;
    else                 dp[i][i + 1] = 3, dp2[i][i + 1] = 2;
  }
  for(int k = 2; k < S.size(); k++) {
    for(int i = k; i < S.size(); i++) {
      if(S[i - k] == S[i]) {
        dp[i - k][i] = dp[i - k + 1][i - 1] + 2;
        merge(dp2[i - k][i], dp2[i - k + 1][i - 1]);
      } else {
        dp[i - k][i] = min(dp[i - k + 1][i], dp[i - k][i - 1]) + 2;
        if(dp[i - k + 1][i] + 2 == dp[i - k][i]) merge(dp2[i - k][i], dp2[i - k + 1][i]);
        if(dp[i - k][i - 1] + 2 == dp[i - k][i]) merge(dp2[i - k][i], dp2[i - k][i - 1]);
      }
    }
  }

  if(dp2[0][S.size() - 1] <= k) {
    cout << "NONE" << endl;
  } else {
    int l = 0, r = S.size() - 1;
    string L, R;
    while(l < r) {
      if(S[l] == S[r]) {
        L += S[l++], R += S[r--];
      } else {
        bool which;
        if(dp[l + 1][r] < dp[l][r - 1]) {
          which = false;
        } else if(dp[l + 1][r] > dp[l][r - 1]) {
          which = true;
        } else if(S[l] < S[r]) {
          if(dp2[l + 1][r] <= k) k -= dp2[l + 1][r], which = true;
          else which = false;
        } else {
          if(dp2[l][r - 1] <= k) k -= dp2[l][r - 1], which = false;
          else which = true;
        }
        if(!which) {
          L += S[l], R += S[l++];
        } else {
          L += S[r], R += S[r--];
        }
      }
    }
    if(l == r) L += S[l];
    reverse(R.begin(), R.end());
    cout << L << R << endl;
  }
}

Measured memory_bytes: 62940
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
using namespace std;
const int N = 2e5+5;
int n,head[N],to[N<<1],nxt[N<<1],x[N],cnt;

void addEdge(int a, int b){
	nxt[++cnt]=head[a];
	head[a]=cnt;
	to[cnt]=b;
}

void dfs(int k, int f){
	x[k] += x[f];
	for(int e=head[k];e;e=nxt[e]){
		if(to[e] == f) continue;
		dfs(to[e], k);
	}
}

int main(){
	scanf("%d", &n);
	int q;
	scanf("%d", &q);
	for(int i=1;i<n;++i){
		int a,b;
		scanf("%d%d", &a, &b);
		addEdge(a,b);
		addEdge(b,a);
	}
	for(int i=0;i<q;++i){
		int a,b;
		scanf("%d%d", &a, &b);
		x[a] += b;
	}
	dfs(1,0);
	for(int i=1;i<=n;++i){
		printf("%d ", x[i]);
	}
	printf("\n");
    return 0;
}


Measured memory_bytes: 13312
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

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

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


double heron(double a,double b, double c){
	double s = (a+b+c)/2;
	return sqrt(s*(s-a)*(s-b)*(s-c));
}


int n;
double x[3],y[3];

int main(){
	cin>>n;
	rep(i,n){
		rep(j,3) cin>>x[j]>>y[j];
		P a(x[0],y[0]),b(x[1],y[1]),c(x[2],y[2]);
		double al = abs(b-c),bl=abs(c-a),cl=abs(a-b);
		double s = heron(al,bl,cl);
		double al2=al*al,bl2=bl*bl,cl2=cl*cl;
		P I = ((16*s*s-bl2*(cl2+al2-bl2)-cl2*(al2+bl2-cl2))*a + bl2*(cl2+al2-bl2)*b + cl2*(al2+bl2-cl2)*c)/(16*s*s);
		printf("%0.3f %0.3f %0.3f\n",I.real(),imag(I),abs(I-a));
	}
	return 0;
}

Measured memory_bytes: 1260