akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,q;
    cin>>n>>q;
    vector<pair<int,pair<int,int>>> v(n);
    for(int i=0;i<n;i++){
        int s,t,x;
        cin>>s>>t>>x;
        v[i]={x,{s,t}};
    }
    sort(v.begin(),v.end());
    set<pair<int,int>> d;
    for(int i=0;i<q;i++){
        int t;
        cin>>t;
        d.insert({t,i});
    }
    int ans[q];
    memset(ans,-1,sizeof(ans));
    for(int i=0;i<n;i++){
        if(d.empty())break;
        int x=v[i].first;
        int s=v[i].second.first;
        int t=v[i].second.second;
        auto it=d.lower_bound({s-x,-1});
        if(it==d.end())continue;
        while((*it).first<t-x){
            ans[(*it).second]=x;
            d.erase(it);
            if(d.empty())break;
            it=d.lower_bound({s-x,-1});
            if(it==d.end())break;
        }
    }
    for(int i=0;i<q;i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<complex>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int main()
{
	int n;
	read(n);
	if(n>=1000)
		printf("ABD\n");
	else
		printf("ABC\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main()
{
    long long int x,t,t2=0;
    scanf("%lld",&x);
    if(x%500==0)
        printf("%lld\n",x*2);
    else
    {
      t=x/500;
       t2=t*1000+x%500-x%5;
        printf("%lld",t2);
    }
    return 0;
}


Measured memory_bytes: 256
import math
N=int(input())
n=math.floor(N/1.08)
N1=math.floor(1.08*n)
N2=math.floor(1.08*(n+1))
 
if N==N1:
  print(n)
elif N==N2:
  print(n+1)
else:
  print(':(')

Measured memory_bytes: 3060
import * as fs from 'fs'

//in
// 7
// beat
// vet
// beet
// bed
// vet
// bet
// beet
//out
// beet
// vet

let input: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const n: number = parseInt(input[0]);
input.shift();
let s: string[] = input.sort();

const counts: any = {};
let maxCnt: number = 0;
for (let i: number = 0; i < n; i++) {
    let key = s[i];
    counts[key] = (counts[key]) ? counts[key] + 1 : 1;
    if (maxCnt < counts[key]) {
        maxCnt = counts[key];
    }
}

const key = Object.keys(counts);
const result = key.filter(key => counts[key] === maxCnt);
console.log(result.join('\n'))

Measured memory_bytes: 113960
#include<bits/stdc++.h>
#define INTMAX 2147483647LL
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define pb push_back
#define re register
#define lc c[x][0]
#define rc c[x][1]
using namespace std;
typedef long long ll;
const double Pi=acos(-1.0);
const int Inf=0x3f3f3f3f;
const int MAXN=4e3+10;
const int MMod=998244353; 
inline int read(){
	re int x=0,f=1,ch=getchar();
	while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-48,ch=getchar();
	return x*f;
}
inline ll readll(){
	re ll x=0,f=1,ch=getchar();
	while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-48,ch=getchar();
	return x*f;
}

int n,K;
int fac[MAXN],inv[MAXN];
inline int Mod(int x){return x<MMod?x:x-MMod;}
inline int Fast_Pow(int x,int y){int res=1;while(y){if(y&1) res=1ll*res*x%MMod;x=1ll*x*x%MMod;y>>=1;}return res;} 
inline int C(int n,int k){if(k<0||n<k) return 0;return 1ll*fac[n]*inv[k]%MMod*inv[n-k]%MMod;}
inline void Init(){
	fac[0]=1;for(int i=1;i<=4000;++i) fac[i]=1ll*fac[i-1]*i%MMod;
	inv[4000]=Fast_Pow(fac[4000],MMod-2);for(int i=3999;i>=0;--i) inv[i]=1ll*inv[i+1]*(i+1)%MMod;
}
int main(){
	Init();
	K=read();n=read();
	//cout<<"*******"<<K<<endl;
	for(int i=2;i<=K*2;++i){
		//cout<<i<<' ';
		int s=0,ans=0,t=0,c;
		for(int j=1;j<=K;++j)
			if(j<=i-j&&i-j<=K&&i-j>=1){if(j!=i-j) ++s;else t=1;}
		c=K-2*s-t;
		
		if(c) ans=C(n+c-1,c-1);
		for(int j=1;j<=s&&j<=n;++j)
			ans=Mod(ans+1ll*C(s,j)*C(n+c-1,j+c-1)%MMod*Fast_Pow(2,j)%MMod);
		
		if(t){
			if(c) ans=Mod(ans+C(n-1+c-1,c-1));
			for(int j=1;j<=s&&j<=n-1;++j)
				ans=Mod(ans+1ll*C(s,j)*C(n-1+c-1,j+c-1)%MMod*Fast_Pow(2,j)%MMod);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
	int n,W;
    cin>>n>>W;
    int*dp = new int[W+1];
    for(int i=1; i<=n; i++)
    {
      int weight , value;
      cin>>weight>>value;
      for(int j=W; j>=weight; j--)
      {
 		dp[j] = max(dp[j-weight] + value, dp[j]);
      }
    }
    cout<<dp[W];
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
using namespace std;

bool used[110000];
vector <int> ve[110000];
int count_[2];
long long ans;
int dd[110000];
bool B;
int n, m;

void dfs(int k) {
	used[k] = true;
	// count_ += 1;
	count_[dd[k]] += 1;
	for (int i = 0; i < (int) ve[k].size(); i++) {
		if (used[ve[k][i]] && dd[ve[k][i]] == dd[k]) {
			B = false;
		}else if (!used[ve[k][i]]) {
			dd[ve[k][i]] = 1 - dd[k];
			dfs(ve[k][i]);
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		ve[x].push_back(y);
		ve[y].push_back(x);
	}
	for (int i = 1; i <= n; i++)
		if (!used[i]) {
			B = true;
			// count_ = 0;
			count_[0] = count_[1] = 0;
			dd[i] = 0;
			dfs(i);
			if (B)
				ans += 1LL * count_[0] * count_[1];
			else
				ans += 1LL * (count_[0] + count_[1]) * (count_[0] + count_[1] - 1) / 2;
			// printf("?? %d %d\n", count_[0], count_[1]);
			// if (ve[])
		}
	cout << ans - m << endl;
	// for ()
}

Measured memory_bytes: 7296
k,s = map(int,input().split())

d = {}
cnt = 0
for x in range(k+1):
    for y in range(x+1):
        z = s - x - y
        if(z >= 0 and z <= y):
            if(x == y and y == z):
                cnt += 1
            elif(x == y or y == z or z == x):
                cnt += 3
            else:
                cnt += 6

print(cnt)



Measured memory_bytes: 9012
# coding: utf-8
# Your code here!

N, M, C = map(int, input().split(" "))
B = list(map(int, input().split(" ")))

ret = 0
for i in range(N):
    A = list(map(int, input().split(" ")))
    F = C
    for j in range(M):
        F += A[j] * B[j]
    if F > 0:
        ret += 1

print(ret)

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

int main(){
  int n;
  string s;
  cin>>n>>s;
  string d="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  vector<char> a;
  for(int i=0; i<s.size(); i++){
    for(int j=0; j<26; j++){
      if(s[i]==d[j])
        a.push_back(d[j+n]);
    }
  }
  for(int i=0; i<s.size(); i++)
    cout << a[i];
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#define M 1000000
using namespace std;

typedef long long ll;
int n,m,V;
map<ll, int> dp;

int rec(ll ma){
  if(dp.find(ma)!=dp.end())return dp[ma];
  
  int mate[4];
  ll k=1;
  for(int i=0;i<4;i++){
    mate[i] = (int)(ma%(1000*k)/k);
    k *= 1000;
  }

  int e = mate[0];
  if(e==5*n+2){
    if((!mate[1] || mate[1] == V-2) && (!mate[2] || mate[2] == V-1)
       && mate[3] == 1){
      return dp[ma] = 1;
    }else return dp[ma] = 0;
  }

  int ed = e%5;
  if(ed < 2){
    int a = (e/5)*3 + 1 + ed;
    int tmp[4]; for(int i=0;i<4;i++)tmp[i] = mate[i];
    tmp[0]++;
    ll t = 0; k = 1;

    for(int i=0;i<4;i++){
      t += tmp[i]*k; k*=1000;
    }
    int res = rec(t);

    if(!mate[ed+1] || !mate[ed+2])return dp[ma] = res;
    for(int i=1;i<4;i++){
      if(1<mate[i] && mate[i] < a-ed)return dp[ma] = 0;
    }

    if(ed == 0 && a!=1 && mate[1] == a 
       && mate[2] == a+1 && mate[3] == a+2)return dp[ma] = res;
    if(ed == 1 && a!=2 && mate[1] == a-1
       && mate[2] == a && mate[3] == a+1)return dp[ma] = res;
    if(ed == 0 && mate[1] == a+1 && mate[2] == a)return dp[ma] = res;
    if(ed == 1 && mate[2] == a+1 && mate[3] == a)return dp[ma] = res;

    if(mate[ed+1] == a)tmp[ed+1] = mate[ed+2];
    else{
      tmp[ed+1] = 0;
      for(int i=1;i<4;i++)if(tmp[i] == a)tmp[i] = mate[ed+2];
    }
    if(mate[ed+2] == a+1)tmp[ed+2] = mate[ed+1];
    else{
      tmp[ed+2] = 0;
      for(int i=1;i<4;i++)if(tmp[i] == a+1)tmp[i] = mate[ed+1];
    }

    t = 0; k = 1;
    for(int i=0;i<4;i++){
      t += tmp[i]*k; k*=1000;
    }
 
    res += rec(t);
    return dp[ma] = res % M;
  }else{
    ed -= 2;
    int a = (e/5)*3 + 1 + ed;
    
    int tmp[4]; for(int i=0;i<4;i++)tmp[i] = mate[i];
    tmp[0]++; tmp[ed+1] = a+3;
    ll t = 0; k = 1;
    for(int i=0;i<4;i++){
      t += tmp[i]*k; k*=1000;
    }
 
    int res = rec(t);
    
    if(!mate[ed+1])return dp[ma] = res;
    if(a!=1 && mate[ed+1] == a)return dp[ma] = res;
    if(a==1 && mate[ed+1] != a)return dp[ma] = res;
    
    for(int i=1;i<4;i++)if(tmp[i] == a)tmp[i] = a+3;
    tmp[ed+1] = mate[ed+1];
    t = 0; k = 1;
    for(int i=0;i<4;i++){
      t += tmp[i]*k; k*=1000;
    }
 
    res = rec(t);
    return dp[ma] = res;
  }
}

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

  if(m==1){
    int res = 1;
    while(n--){
      res <<= 1; res %= M;
    }
    cout << res << endl;
  }else{
    V = (n+1)*(m+1);
    ll v = 0, k = 1;
    for(int i=0;i<4;i++){
      v += i*k; k*=1000;
    }

    cout << rec(v) << endl;
    /*
      for(map<vector<int>,int>::iterator it=dp.begin();it!=dp.end();it++){
      for(int i=0;i<4;i++)cout << (*it).first[i] << " ";
      cout << (*it).second << endl;
      }
    */
  }
}

Measured memory_bytes: 17324
n = gets.to_i
p = gets.strip.split.map(&:to_i)
c = 0

if p == p.sort
  puts "YES"
  exit
end

(0..n-1).each do |i|
  if p[i] != i + 1  
    c = c + 1
    if c > 2
      puts "NO"
      exit
    end
  end
end
puts "YES"

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

int main(){
  long long a,b,k;
  string s,t;
  cin >> a >> b >> k;
  if (k > a+b)
    cout << "0 0" << endl;
  else if (k > a)
    cout << "0 " << (a+b-k) << endl;
  else
    cout << a-k << " " << b << endl;
  return 0;
}

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

void solve(long long A, long long B)
{
    if (A + B <= 3)
    {
        cout << A + B << endl;
    }
    else
    {
        cout << max(A - B, B - A) << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 384
// motatoes cp snippet
#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define ll long long

#define forr(a,b,v) for(int v=a; v<=b; v++)
#define ford(a,b,v) for(int v=a; v>=b; v--)

// https://www.topcoder.com/community/competitive-programming/tutorials/power-up-c-with-the-standard-template-library-part-1/#map
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())


string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

// get default value from map type
template<class K, class V>
V get(map<K,V> m, K k, V def) {
    if (m.find(k) != m.end()) {
        return m[k];
    } else {
        return def;
    }
}

// <geometry>
const double PI = acos(-1.0);

double toDegreeFromMinutes(double minutes) {
  return (minutes/60);
}

double toRadians(double degree) {
  return (degree * PI/180.0);
}

double toDegree(double radian) {
  if (radian < 0) radian += 2 * PI;
  return (radian * 180 / PI);  
}

double fixAngle(double A) {
  return A > 1 ? 1 : (A < -1 ? -1 : A);
}

// sin(A)/a = sin(B)/b = sin(C)/c
double getSide_a_bAB(double b, double A, double B) {
  return (sin(A)*b)/sin(B);
}

double getAngle_A_abB(double a, double b, double B) {
  return asin( fixAngle(  (a*sin(B))/b ));  
}

// a^2 = b^2 + c^2 - 2*b*c*cos(A)
double getAngle_A_abc(double a, double b, double c) {
  return acos( fixAngle(  (b*b*c*c-a*a) / (2*b*c)  ) );  
}
// </geometry>


#define INF 1e9+5

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

    int n;
    int k;


    cin >> n >> k;  

    int h[n+k+5];

    for (int i=1; i<=n; i++) {
        cin >> h[i];
    }
    vector<int> dp(n+k+5, INF) ;
    dp[1] = 0;

    for (int i=1; i<n+1; i++) {
        for (int kk=1; kk<=k; kk++) {
            // cout << dp[i] << " " << abs(h[i] - h[i+kk]) << endl;
            dp[i+kk] = min(dp[i+kk], dp[i] + abs(h[i] - h[i+kk]));
        }
    }
    // cout << to_string(dp) << endl;
    cout << dp[n];

    

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second

struct two
{
	int a, b;
	two() : a(0), b(0) {}
	void update(int x)
	{
		if (x > a) swap(x, a);
		if (x > b) swap(x, b);
	}
	void merge(two t)
	{
		update(t.a);
		update(t.b);
	}
};

int main()
{
	#ifdef DGC
		freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(1<<n);
	vector<two> dp(1<<n);
	for (auto &i : a)
	{
		cin >> i;
		dp[&i-&a[0]].update(i);
	}
	
	for (int j = 0; j < n; ++j)
		for (int i = 0; i < 1<<n; ++i)
			if (~i>>j&1)
				dp[i|1<<j].merge(dp[i]);

	dp.emplace_back();
	for (int i = 1; i < 1<<n; ++i)
	{
		cout << dp[i].a+dp[i].b << "\n";
		if (dp[i].a+dp[i].b > dp[i+1].a+dp[i+1].b)
			dp[i+1] = dp[i];
	}

	return 0;
}


Measured memory_bytes: 7676
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int D;
  cin>>D;
  if(D==25)cout<<"Christmas"<<endl;
  else if(D==24)cout<<"Christmas Eve"<<endl;
  else if(D==23)cout<<"Christmas Eve Eve"<<endl;
  else if(D==22)cout<<"Christmas Eve Eve Eve"<<endl;
}


Measured memory_bytes: 256
n=int(input())
x=[int(x) for x in input().split()]
c=0
x.sort()
for i in  range(len(x)):
  for j in  range(i+1,len(x)):
    for k in range(j+1,len(x)):
      if x[i]+x[j]>x[k] and  x[i]!=x[j]  and x[j]!=x[k] and x[i]!=x[k]:
        c+=1
        #print(i+1,j+1,k+1)
print(c)

Measured memory_bytes: 68032
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
int main(int argc, char const *argv[]) {
  int x = read(), y = read();

  if (abs(x) > abs(y)) {
    printf("%d\n", (x > 0) + (y > 0) + abs(x) - abs(y));
  } else if (abs(x) < abs(y)) {
    printf("%d\n", (x < 0) + (y < 0) + abs(y) - abs(x));
  } else {
    printf("%d\n", x != y);
  }

  return 0;
}

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

using namespace std;

int main()
{
	int n, W;
	cin >> n >> W;
	int w[n], v[n];
	map<int, bool> m;
	for(int i=0;i < n; i++)
		cin >> w[i] >> v[i];
	int MAX = (int)1e5 + 5;
	long long dp[MAX];
	memset(dp, 0, sizeof(dp));
	for(int i =0;i<n;i++)
	{
		for(int j=MAX - 1;j>=0;j--)
		{
		    long long temp = dp[j];
			if(j - v[i] >= 0 && dp[j-v[i]])
			{
				dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
				if(dp[j] == 0)
					dp[j] = dp[j - v[i]] + w[i];
			}
			if(dp[j] > W)
			{
				dp[j] = temp;
			}
		}
		if(dp[v[i]] > 0)
			dp[v[i]] = min(dp[v[i]], (long long)w[i]);
		else
			dp[v[i]] = w[i];
	}
	int ans = MAX-1;
	while(dp[ans] == 0 && ans >= 0)
		ans--;
	ans = max(ans, 0);
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll dp[ohara][3];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    dp[0][1]=-a[0];
    dp[0][2]=a[0];
    rrep(i,1,n){
        if(i!=n-1)dp[i][1]=max(dp[i-1][1]+a[i],dp[i-1][2]-a[i]);
        dp[i][2]=max(dp[i-1][1]-a[i],dp[i-1][2]+a[i]);
    }
    ans=dp[n-1][2];
    Cout(ans);
    return 0;
}


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

using namespace std;

int main() {

	int N;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}

	int buf = 0;
	int res = 0;
	int h = H[0];
	for (int i = 1; i < N; ++i) {
		if (H[i] <= h) {
			++buf;
			h = H[i];
		}
		else {
			buf = 0;
			h = H[i];
			continue;
		}

		if (buf > res) {
			res = buf;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 640
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll ans = 0;
    ll N = S.size();
    rep(i,0,N/2){
        if(S[i] != S[N-1-i]) ans++;
    }
    print(ans);

    

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

const int MaxN = 505;

int n, h;
int in[MaxN], out[MaxN], ok[MaxN], fa[MaxN];

int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }

void Init()
{
	scanf("%d%d", &n, &h);
	for (int i = 1; i <= (h << 1); ++i)
		fa[i] = i;
	for (int i = 1; i <= n; ++i)
	{
		int a, b, c, d, l, r;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		l = (c == 0) ? h + a : c;
		r = (d == 0) ? b : h + d;
		++out[l];
		++in[r];
		if (Find(l) != Find(r))
			fa[Find(l)] = Find(r);
	}
}	

int Main()
{
	for (int i = 1; i <= h; ++i)
		if (out[i] > in[i])
			return puts("NO");
	for (int i = h + 1; i <= (h << 1); ++i)
		if (in[i] > out[i])
			return puts("NO");
	for (int i = 1; i <= (h << 1); ++i)
		if (in[i] != out[i])
			ok[Find(i)] = true;
	for (int i = 1; i <= (h << 1); ++i)
		if (Find(i) == i && !ok[i] && in[i] + out[i] != 0)
			return puts("NO");
	return puts("YES");
}

int main()
{
	Init();
	Main();
	return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    ll money = 1000, num = 0;

    rep(i, n - 1) {
        if (a[i] > a[i + 1]) {
            money += num * a[i];
            num = 0;
        } else {
            num += money / a[i];
            money %= a[i];
        }
    }

    money += num * a[n - 1];
    num = 0;
    cout << money << endl;
    return 0;
}



Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	static PrintWriter out;
	static Scanner sc;
	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int t;
		boolean f = true;
		while(n-->0) {
			t = sc.nextInt();
			if(t%2 == 0) {
				if(t%3 != 0 && t%5 != 0) {
					f = false;
				}
			}
		}
		out.println(f?"APPROVED":"DENIED");
		out.close();
	}
	static class Scanner{
		BufferedReader br;
		StringTokenizer st;
		public Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));			
		}
		private String next() throws IOException{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
	}
}


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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=3005;
const int mod=998244353;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int n,m;
int a[N];
int f[N][N];
int mi[N];

int main()
{
    read(n),read(m);
    Rep(i,1,n)read(a[i]);
    f[0][0]=1;
    Rep(i,1,n){
        Rep(j,0,m){
            f[i][j]=f[i-1][j]*2%mod;
            if(j>=a[i])f[i][j]+=f[i-1][j-a[i]],f[i][j]%=mod;
        }
    }
    printf("%d\n",f[n][m]);
    return 0;
}

Measured memory_bytes: 38936
// Last Change: 04/01/2019 19:20:53.
#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

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

  ll minNum = 1000000009, maxNum = 0;
  ll ipt;
  for (int i = 0; i < N; ++i) {
    cin >> ipt;
    minNum = min(minNum, ipt);
    maxNum = max(maxNum, ipt);
  }

  cout << maxNum - minNum << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
int book[12];
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    book[a]++;
    book[b]++;
    book[c]++;
    if(book[5]==2&&book[7]==1)
        printf("YES");
    else printf("NO");
    return 0;
}



Measured memory_bytes: 256
W,H,x,y,r,=map(int,input().split())
if (x-r<0 or x+r>W) or (y-r<0 or y+r>H):
    print ("No")
elif (x-r>=0 and x+r<=W) or (y-r>=0 and y+r<=H):
    print ("Yes")


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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 9;
int par[N];

int fin(int x){ 
  if(x == par[x]) return x;
  return par[x]=fin(par[x]);
}

int unite(int a, int b){ 
  a = fin(a);
  b = fin(b);
  if(a == b) return 0;
  par[a]=b;
  return 1;
}

struct Edge{  
  int ai;
  int bi;
  ll wei;
  bool operator< (const Edge &T) const {
    return wei < T.wei;
  }
};

vector<Edge> check;

ll a[N];
ll d;

void solve(int l, int r){
  if(l == r) return;
  int mid = (l + r) / 2;
  int i1 = l;
  int i2 = mid + 1;
  for(int j = l + 1; j <= mid ; j ++ ){
    if(a[j] - j * 1ll * d < a[i1] - i1 * 1ll * d){
      i1 = j;
    }
  }
  for(int j = mid + 2; j <= r; j ++ ){
    if(a[j] + j * 1ll * d < a[i2] + i2 * 1ll * d){
      i2 = j;
    }
  }
  for(int i = l ; i <= mid ; i ++ ){
    check.push_back({i,i2,a[i]+a[i2]+(i2-i)*1ll*d});
  }
  for(int i = mid + 1; i <= r; i ++ ){
    check.push_back({i,i1,a[i]+a[i1]+(i-i1)*1ll*d});
  }
  solve(l,mid);
  solve(mid+1,r);
}

int main(){
  fastIO;
  int n;
  cin >> n >> d;
  for(int i = 1; i <= n; i ++ ){
    cin >> a[i];
    par[i]=i;
  }
  solve(1,n);
  sort(check.begin(), check.end());
  ll ans = 0;
  for(auto p : check){
    ans += p.wei * 1ll * unite(p.ai, p.bi);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 70240
#include <iostream>
#include <vector>

using namespace std;

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

    int n;
    cin >> n;

    vector<int> v(n);

    for(auto &a:v)
        cin >> a;

    if(n & 1){
        for (int i = n - 1 - !(n & 1);i >= 0;i-=2){
            cout << v[i] << " ";
        }

        for (int i = 1; i < n;i += 2){
            if(i != 1)
                cout << " ";
            cout << v[i];
        }
    }else{
        for (int i = n - 1 - (n & 1);i > 0;i-=2){
            cout << v[i] << " ";
        }

        for (int i = 0; i < n;i += 2){
            if(i != 0)
                cout << " ";
            cout << v[i];
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2944
def partition(data, left, right):
    pivot = data[right]
    i = left - 1
    for j in range(left, right):
        if data[j] <= pivot:
            i += 1
            data[i], data[j] = data[j], data[i]
    data[i+1], data[right] = data[right], data[i+1]
    return i+1

def main():
    num = raw_input()
    num_list = raw_input().split()
    num_list = map(int, num_list)

    index = partition(num_list, 0, len(num_list)-1)
    num_list = map(str, num_list)
    num_list[index] = "[" + num_list[index] + "]"
    print " ".join(num_list)

if __name__ == "__main__":
    main()

Measured memory_bytes: 17808
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,n,s=0,tp; cin>>h>>n;
  for(int i=0; i<n; ++i) {
    cin>>tp, s+=tp;
    if(s >= h) {cout<<"Yes"; return 0;}
  }
  cout<<"No";
  return 0;
}


Measured memory_bytes: 256
from collections import deque

s = deque(input())
n = int(input())
q_list = [input().split() for i in range(n)]
count = 1
for i in q_list:
    if i[0] == '1':
        count *= -1
    else:
        if i[1] == '1':
            if count == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if count == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])
if count != 1:
    s.reverse()
print(*s, sep='')


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

int main() {
 
  int H,W;
  cin >> H >> W;
    
  for(int i = 0; i < W+2; i++){
  	cout << "#"; 
  }  
  
  cout << endl;
  
  
  for(int i = 0; i < H; i++){
  	cin >> tmp ;
    cout << "#" << tmp << "#" <<endl;
  }
    
    
   for(int i = 0; i < W+2; i++){
  	cout << "#" ;
  } 
      
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<pair<long long, long long>> t;
	for (auto i = 0; i < N; ++i)
	{
		long long A, B;
		cin >> A >> B;
		t.push_back(make_pair(B, A));
	}

	sort(t.begin(), t.end());

	auto c = 0ll;
	auto result = "Yes";
	for (auto i = 0; i < N; ++i)
	{
		auto& p = t[i];
		c += p.second;
		if (c > p.first)
		{
			result = "No";
		}
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 6520
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    
    int ans = 0;
    for (int i = S.length()-2; i >= 2; i-=2) {
      if (S.substring(0, i/2).equals(
        S.substring(i/2, i))) {
        ans = i;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
x, y = map(int, input().split())

if y > x * 4:
    print("No")
else:
    for i in range(x + 1):
        if 2 * i + 4 * (x - i) == y:
            str = 'Yes'
            break
        else:
            str = 'No'

    print(str)


Measured memory_bytes: 61732
#include <iostream>
#include <stdio.h>
#include <math.h>
#define eps 1e-8

using namespace std;

struct vec2d{
	double x, y;
	vec2d(){}
	vec2d(double x, double y){
		this->x = x, this->y = y;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec2d operator+(vec2d ope){
		return vec2d(add(x, ope.x), add(y, ope.y));
	}
	vec2d operator-(vec2d ope){
		return vec2d(add(x, -ope.x), add(y, -ope.y));
	}
	vec2d operator*(double t){
		return vec2d(x*t, y*t);
	}
	vec2d operator/(double t){
		return vec2d(x/t, y/t);
	}
	double dot(vec2d ope){
		return add(x*ope.x, y*ope.y);
	}
	double cross(vec2d ope){
		return add(x*ope.y, -y*ope.x);
	}
	double norm(){
		double d2 = dot(*this);
		if(d2 > 0) return sqrt(d2);
		return 0.0;
	}
};

double distPP(vec2d p, vec2d q){
	return (p-q).norm();
}

vec2d p[3];

vec2d getcenter(int i, double r)
{
	vec2d a, b;
	a = p[(i+1)%3] - p[i], b = p[(i+2)%3] - p[i];
	double th = acos(a.dot(b) / (a.norm() * b.norm()));
	
	a = a / a.norm();
	if(a.cross(b) < 0) b = vec2d(a.y, -a.x);
	else b = vec2d(-a.y, a.x);
	
	vec2d ret = p[i];
	ret = ret + a * r / tan(th/2);
	ret = ret + b * r;
	return ret;
}

bool check(double r)
{
	vec2d c[3];
	for(int i = 0; i < 3; i++) c[i] = getcenter(i, r);
	return distPP(c[0], c[1]) >= 2*r || distPP(c[1], c[2]) >= 2*r || distPP(c[2], c[0]) >= 2*r;
}

int main(void)
{
	for(int i = 0; i < 3; i++){
		cin >> p[i].x >> p[i].y;
	}
	
	double L = distPP(p[0], p[1]) + distPP(p[1], p[2]) + distPP(p[2], p[0]);
	double S = fabs((p[1]-p[0]).cross(p[2]-p[0]) / 2);
	double R = 2*S/L;
	
	double ub = R, lb = 0, mid;
	for(int i = 0; i < 100; i++){
		mid = (ub + lb) * 0.5;
		if(check(mid)) lb = mid;
		else ub = mid;
	}
	printf("%.11f\n", (ub+lb)*0.5);
	return 0;
}

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

vector<int> Input(const int n)
{
    vector<int> W;
    for(int i = 0; i < n; i++){
        int w;
        cin >> w;
        W.push_back(w);
    }
    return W;
}
 
bool IsAllLoaded(int P, vector<int>& W, int k)
{
    int TrackIndex = 0;
    int CurrentSum = 0;
    int i = 0;
    for(i = 0; i < W.size(); i++){
        if(W[i] > P){
            return false;
        }
        if(CurrentSum + W[i] > P){
            TrackIndex++;
            if(TrackIndex == k){
                return false;
            }
            CurrentSum = 0;
        }
        CurrentSum += W[i];
    }
    return true;
}
 
int Calc(vector<int>& W, int k)
{
    int Sum = accumulate(W.begin(), W.end(), 0 );
    int max = *std::max_element(W.begin(), W.end());
    int P = std::max((Sum + k - 1) / k, max);
    while(!IsAllLoaded(P, W, k)){
        P++;
    }
    return P;
}
 
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> W = Input(n);
    int P = Calc(W, k);
    cout << P << endl;
    return 0;
}

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

int main(){
  int d,n;
  cin >> d >> n;
  if(n==100){
    n = 101;
  }
  if(d==0){
    cout << n;
  }else if(d==1){
    cout << 100*n;
  }else{
    cout << 10000*n;
  }
}

Measured memory_bytes: 256
/*
  B - Template Matching
  <http://abc054.contest.atcoder.jp/tasks/abc054_b>
*/

#include <stdio.h>

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

  int N,M;
  int i,j,k,l;
  char A[50][51],B[50][51];
  int judge;

  scanf("%d %d", &N, &M);
  for( i=0; i<N; i++ ){
    scanf("%s", A[i]);
  }
  for( i=0; i<M; i++ ){
    scanf("%s", B[i]);
  }


  for( i=0; i<N; i++ ){
    for( j=0; j<N; j++ ){
      judge = 1;
      for( k=0; k<M; k++ ){
        for( l=0; l<M; l++ ){
          if( i+k >= N ){
            judge = 0;
            break;
          }
          if( j+l >= N ){
            judge = 0;
            break;
          }
          if( A[i+k][j+l] != B[k][l] ){
            judge = 0;
            break;
          }
        }
      }
      if( judge == 1 ){
        printf("Yes\n");
        return 0;
      }
    }
  }

  printf("No\n");
  return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(1 == N)
            System.out.println("Hello World");
        else {
            int A, B;
            A = sc.nextInt();
            B = sc.nextInt();
            System.out.println(A+B);
        }
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
int main()
{
	dhoom;
	ll b , a;
	cin >> a >> b;
	cout << (b - a) * (b - a  + 1) / 2 - b  << endl;
	
	return 0;
} 



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    double a, b, c;
    cin >> a >> b >> c;
    c = (c * acos(-1)) / 180;
    cout << (a * b * sin(c)) / 2 << endl;
    cout << a + b + sqrt(a * a + b * b - 2 * b * a * cos(c)) << endl;
    cout << b * sin(c) << endl;
}


Measured memory_bytes: 3448
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char a[105];
int c=99999,b;
int main()
{
	cin>>a;
	for(int i=0;i<101;i++)
	  {
	  	if(a[i]=='C')
		{
	  	  c=i;
	  	  break;
		}
	  }
	for(int i=0;i<101;i++)
	  {
	  	if(a[i]=='F')
	  	  b=i;
	  }
	if(c>=b)
	printf("No\n");
	else
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define MAX 100005
#define NIL (-1)
using namespace std;

struct Node{
    int parent, left, right;
};

Node T[MAX];
int n, D[MAX];

int getDepth(int u){
    int d = 0;
    while(T[u].parent != NIL){
        u = T[u].parent;
        d++;
    }
    return d;
}

void setDepth(int u, int p){
    D[u] = p;
    if(T[u].right != NIL) setDepth(T[u].right, p);
    if(T[u].left != NIL) setDepth(T[u].left, p+1);
}

void printChildren(int u){
    int c = T[u].left;
    while(c != NIL){
        cout << c;
        c = T[c].right;
        if(c != NIL) cout << ", ";
    }
}

int main(){
    int n, id, k, i, j, tmp;
    cin >> n;
    for(i = 0; i < n; i++){
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }
    for(i = 0; i < n; i++){
        cin >> id;
        tmp = id;
        cin >> k;
        if(k == 0){
            T[id].left = NIL;
        }
        if(k > 0){
            cin >> T[id].left;
            id = T[id].left;
            T[id].parent = tmp;
            if(k > 1){
                for(j = 0; j < k - 1; j++){
                    cin >> T[id].right;
                    id = T[id].right;
                    T[id].parent = tmp;
                }
            }
            T[id].right = NIL;
        }
    }
    for(i = 0; i < n; i++){
        if(T[i].parent == NIL) j = i;
    }
    setDepth(j, 0);
    for(i = 0; i < n; i++){
        cout << "node " << i;
        cout << ": parent = " <<  T[i].parent;
        cout << ", depth = " << D[i] << ", ";
        if(T[i].parent == NIL) cout << "root, [";
        else if(T[i].left == NIL) cout << "leaf, [";
        else cout << "internal node, [";
        printChildren(i);
        cout << "]\n";
    }
    return 0;
}


Measured memory_bytes: 7768
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vvll vector<ll>
#define vll(a) vector<ll> a(MAXN)
#define pb push_back
#define fo(a) for(auto&a1:(a))
#define fd(a,b) for(int i=(a);i>=(b);i--)
#define fk(a,b) for(int k=(a);k<(b);k++)
#define fj(a,b) for(int j=(a);j<(b);j++)
#define f(a,b) for(ll i=(a);i<(b);i++)
#define forni(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define fdk(a,b) for(int k=(a);k>=(b);k--)
#define fdj(a,b) for(int j=(a);j>=(b);j--)
#define ri(n) scanf("%d",&(n));
#define rll(n) scanf("%lld",&(n));
#define T(t) int t;scanf("%d",&(t));while((t)--)
#define MAXN 10000001
#define MAXN2 10000005
#define pll pair<ll,ll>
#define PI 3.14159265
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const ll mod=1000000007;
int main()
{
    ll n;
    cin>>n;
    ll h[n];
    f(0,n)
    cin>>h[i];
    ll dp[n]={INT_MAX};
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    f(2,n)
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n-1]<<"\n";
    return 0;
}


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

int main() {
  char a;
  cin >> a;
  int i;
  i = (int)(a-'A'+1);
  
  if(1<=i && i<=26) cout << 'A' << endl;
  else cout << 'a' << endl;
	return 0;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int n; cin >> n;
  ll ans = 0;
  multiset<int> st;
  rep(i, n) {
    ll a; cin >> a;
    if (a>=n*n) {
      ll p = a-n*n;
      ll q = p/(n+1);
      ans += q*(n+1);
      a -= q*(n+1);
    }
    st.insert(a);
  }
  ll top = n-1;
  while(true) {
    auto it = st.end();
    it--;
    ll ma = *it;
    debug(ma);
    if (ma <= top) {
      cout << ans << endl;
      return 0;
    }
    it = st.erase(it);
    st.insert(ma-n-1);
    ans++;
    top--;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include<cstdio>
//#include<cstring>
using namespace std;
#define fi first
#define se second
#define pii pair<ll,ll>
#define pll pair<long long ,long long>
#define mp make_pair
typedef long double DB;
typedef long long ll;
const int maxn=1e5+15;
const int maxm=10;
const int maxe=20005;
const int mod=998244353;
const int inf=0x3f3f3f3f;
int n,m;
int sum[maxn];
void init(){
    for(int i=1;i<maxn;i++){
        int ii=i;
        int cnt=0;
        while(ii){
            cnt+=ii%10;
            ii/=10;
        }
        sum[i]=cnt;
    }
}

int main(){
    init();
    scanf("%d",&n);
    int ans=0x3f3f3f3f;
    for(int i=1;i<n;i++){
        int j=n-i;
        ans=min(sum[i]+sum[j],ans);
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};


vector<int> dist;
vector<vector<edge>> e;
int N;

int dfs1(int p, int par = -1)
{
    int& res = dist[p];
    for (auto x : e[p]) {
        if (x.to == par) continue;
        res = max(res, x.cost + dfs1(x.to, p));
    }
    return res;
}

int dfs2(int p, int d_par = 0, int par = -1)
{
    vector<pair<int, int>> d;
    d.emplace_back(0, -1);
    for (auto x : e[p]) {
        if (x.to == par) d.emplace_back(d_par + x.cost, x.to);
        else d.emplace_back(dist[x.to] + x.cost, x.to);
    }
    sort(d.rbegin(), d.rend());
    int res = d[0].first + d[1].first;
    for (auto x : e[p]) {
        if (x.to == par) continue;
        res = max(res, dfs2(x.to, d[x.to == d[0].second].first, p));
    }
    return res;
}

int main()
{
    cin >> N;
    dist.resize(N, 0);
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    dfs1(0);
    cout << dfs2(0) << endl;
}


Measured memory_bytes: 27324
#include <stdio.h>
#include <string.h>


int main(){
char temp[103],temp2[103];
int angka[100][103];
int hasil[50][103];
int length[50];



int i,j;

int ind;

for(i=0;i<50;i++){
    for(j=0;j<103;j++){
        angka[i][j]=0;
    }
}
int n;
scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%s",temp);
    int panjang1=strlen(temp);
    int ctr=0;
    for(j=panjang1-1;j>=0;j--){
        angka[i*2][ctr]=temp[j]-'0';
        ctr++;
    }
    scanf("%s",temp2);
    int panjang2=strlen(temp2);
    ctr=0;
    for(j=panjang2-1;j>=0;j--){
        angka[i*2+1][ctr]=temp2[j]-'0';
        ctr++;
    }

    length[i]=panjang1;
    if(panjang2>panjang1){
        length[i]=panjang2;
    }
    if(length[i]<=80){
        for(j=0;j<length[i]+1;j++){
                hasil[i][j]=0;
        }
        hasil[i][length[i]+1]=-1;
        int k;
        for(j=0;j<length[i];j++){
            hasil[i][j]+=angka[i*2][j];
            hasil[i][j]+=angka[i*2+1][j];
        }

        for(j=0;j<length[i];j++){
            hasil[i][j+1]+=hasil[i][j]/10;
            hasil[i][j]=hasil[i][j]%10;
        }
        if(hasil[i][length[i]]!=0){
            length[i]++;
        }
    }else{
        hasil[i][length[i]-1]=-1;
    }
}


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

    if(length[i]<=80){
    for(j=length[i]-1;j>=0;j--){
            printf("%d",hasil[i][j]);
    }
    }else{
        printf("overflow");
    }
    printf("\n");
}


return 0;
}



Measured memory_bytes: 2092
n,x,y=map(int,input().split())
k=[0]*n
for i in range(1,n):
  for j in range(1,n-i+1):
    t=min(j,abs(i-x)+abs(i+j-y)+1)
    k[t]+=1
for i in range(1,n):
  print(k[i])

Measured memory_bytes: 3444
url = "https://atcoder.jp//contests/abc113/tasks/abc113_c"

def main():
    t = list(map(int, input().split()))
    town = {k: [] for k in range(1, t[0]+1)}
    all_town = []
    for _ in range(t[1]):
        tmp = list(map(int, input().split()))
        all_town.append(tmp)
        town[tmp[0]].append(tmp[1])
    ans = {}
    for k in town:
        town[k].sort()
        tmp_dic = {town[k][i]: str(k).zfill(6)+str(i+1).zfill(6) for i in range(len(town[k]))}
        ans.update(tmp_dic)
    for at in all_town:
        print(ans[at[1]])


if __name__ == '__main__':
    main()


Measured memory_bytes: 136724
def func(a):
    if a % 2 == 0:
        return a // 2
    else:
        return 3 * a + 1

s = int(input())
res = [s]
idx = 0
for i in range(2, 10 ** 6 + 1):
    s = func(s)
    if s in res:
        idx = i
        break
    res.append(s)
print(idx)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;

    int ans = 0;
    if(s[0] == '1') ans++;
    if(s[1] == '1') ans++;
    if(s[2] == '1') ans++;

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int number_r, number_x_2000, number_d, i, number_x_next;
  scanf("%d %d %d", &number_r, &number_d, &number_x_2000);
  number_x_next = number_x_2000;
  for(i = 0; i < 10; i++) {
    number_x_next = number_r * number_x_next - number_d;
    printf("%d\n", number_x_next);
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;


int main(){

  int n,p;
  int have[50];
  int num;
  int cup;

  while(cin >> n >> p){
    if(n==0 && p==0){break;}

    for(int i=0; i<n; i++){ have[i]=0; }
    num=0;
    cup = p;
    //reset


    while(have[num%n]!=p){
      if(cup!=0){
	cup--;
	have[num%n]++;
      }
      else{
	cup = have[num%n];
	have[num%n]=0;
      }
      
      num++;

    }


    cout << num%n << endl;

  }



  return 0;
}

Measured memory_bytes: 1160
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h1,m1,h2,m2,k = inpl()
if m1 > m2:
    m2 += 60
    h2 -= 1
print((h2-h1)*60+(m2-m1)-k)

Measured memory_bytes: 72556
N,M = map(int,input().split())
A = []
B = []
c = 0
for i in range(N):
  A.append([int(x) for x in input().split()])
  
for j in range(M):
  b = int(input())
  B.append(b)
  
for i in range(N):
  for j in range(M):
    c +=  A[i][j] * B[j]
  print(c)
  c = 0


Measured memory_bytes: 6016
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int cnt[30];
int main(){
	std::ios::sync_with_stdio(false);
	int h,w,i,j,c=0,c1=0;
	string s;
	cin>>h>>w;
	rep(i,h){
		cin>>s;
		rep(j,w){
			cnt[s[j]-'a']++;
		}
	}	
	rep(i,26){
		if(cnt[i]%4==1||cnt[i]%4==3)
			c++;
		else if(cnt[i]%4==2)
			c1++;
	}
	//cout<<c<<" "<<c1<<endl;
	if(h%2==1&&w%2==1){
		if(c==1&&c1<=h/2+w/2){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	else if(h%2==0&&w%2==1){
		if(c==0&&c1<=h/2){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	else if(w%2==0&&h%2==1){
		if(c==0&&c1<=w/2){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	else{
		if(c==0&&c1==0){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;

int main(){
    double l;
    cin >> l;
    cout << setprecision(10) << fixed << l/3 * l/3 * l/3 << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	long long int N;
	cin >> N;
	long long int Li = 2;
	long long int Li1 = 1;
	long long int Li2 = Li1 + Li;
	for (int i = 0; i < N - 2; i++) {
		Li = Li1;
		Li1 = Li2;
		Li2 = Li1 + Li;
	}
	if (N == 1) {
		cout << Li1 << endl;
	}
	else if (N == 2) {
		cout << Li2 << endl;
	}
	else { 
		cout << Li2 << endl; 
	}
	return 0;
}

Measured memory_bytes: 3628