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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;


ll int digit(ll int num)
{
    ll int m,ini=0;
    while(num)
    {
        m=num%10;
        num/=10;
        ini++;
    }
    return ini;
}


int arr[g_size];



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

	ll int n,m,T,res,ini=0,num,nex;

	ll int maxi=-mx,mini=mx,count=0;

	ll int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];


	cin>>n;

    num=sqrt(n);

    rf(i,num,1){
        if(n%i==0) {
            m=i;
            break;
        }
    }

    ll int x=n/m;
    res=digit(x);
    nex=digit(m);
    cout<<max(res,nex)<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll p[3][4005];
ll func(char a,char b){
	if((a=='0'&&b=='1')||(a=='1'&&b=='0'))
	return 2;
	if((a=='1'&&b=='2')||(a=='2'&&b=='1'))
	return 0;
	else
	return 1;
}
void solve(){
	ll n,res=0;
	string s;
	cin>>n>>s;
	for(ll i=0;i<n;i++){
		p[0][i+1]=p[0][i];
		p[1][i+1]=p[1][i];
		p[2][i+1]=p[2][i];
		if(s[i]=='R'){
		    p[0][i+1]++;
		    s[i]='0';
	    }
		else if(s[i]=='G'){
		    p[1][i+1]++;
		    s[i]='1';
	    }
		else{
		    p[2][i+1]++;
		    s[i]='2';
	    }
	}
	for(ll i=0;i<n;i++)
	for(ll j=i+1;j<n;j++)
	if(s[i]!=s[j]){
	    res+=p[func(s[i],s[j])][n]-p[func(s[i],s[j])][j+1];
	    if(2*j-i<n&&s[2*j-i]==char(func(s[i],s[j])+'0'))
	    res--;
    }
    cout<<res;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll qc=1;
	for(ll i=1;i<=qc;i++)
	solve();
}


Measured memory_bytes: 3752
//  atcodder.xcode
//  main.cpp
//  Created by conan1024hao on 2019/11/11.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリ
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> b(m);
    for(int i=1;i<=m;i++)
        cin>>b[i];
    int A[30][30];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>A[i][j];
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        int sum=c;
        for(int j=1;j<=m;j++){
            sum+=A[i][j]*b[j];
        }
        if(sum>0)
            cnt++;
    }
    cout<<cnt<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



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

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define DOUBLE fixed << setprecision(10)
#define fi first
#define se second
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };
template <typename T>
bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
};
template <typename T>
bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
};
void Pvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void Pvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Ps(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void Pvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

void Yay(bool x) {
	if (x) cout << "Yay!\n";
	else cout << ":(\n";
}


ll  n, m, r, l, k, h, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s,t;

void INIT() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << DOUBLE;
}

int c(ll a,ll b){
    ll rec=1;
    for(int i=0;(1<<i)<=b;i++){
        if(b>>i&1) rec=rec*a%mod;
        a=a*a%mod;
    }
    return rec%mod;
}

int main() {
    INIT();
    ll a,b;cin>>a>>b;
    cout<<c(a,b)<<endl;
    return 0;
}



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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))

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

    int n, m;
    cin >> n >> m;
    int A[n] = {};
    FOR(i, 0, m) {
        int a, b;
        cin >> a >> b;
        A[a-1]++;
        A[b-1]++;
    }
    FOR(i, 0, n) {
        cout << A[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

template<typename T>
struct BIT {
	int n;
	vector<T> d, dd;
	BIT(int n=0):n(n),d(n+1),dd(n+1) {}
	void add(int i, T x=1) {
		i++;
		for (int j=i; j <= n; j += j&-j) {
			d[j] += x;
			dd[j] += x*(j-i+1);
		}
	}
	T sum(int i) {
		i++;
		T x = 0;
		for (; i; i -= i&-i) {
			x += d[i];
		}
		return x;
	}
	T sum(int l, int r) {//l<=i<=r
		return sum(r) - sum(l-1);
	}
	T ssum(int i) {
		i++;
		T x = 0;
		for (int j=i; j; j -= j&-j) {
			x += dd[j] + d[j]*(i-j);
		}
		return x;
	}
};

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int q;
	cin>>q;
	vector<int> c(26);
	vector<BIT<int>> bit(26, BIT<int>(n));
	rep(i, n){
		int ci=s[i]-'a';
		bit[ci].add(i, 1);
	}
	rep(_, q){
		int a;
		cin>>a;
		if(a==1){
			int i;
			char c;
			cin>>i>>c; i--;
			int ci=s[i]-'a';
			bit[ci].add(i, -1);
			ci=c-'a';
			bit[ci].add(i, 1);
			s[i]=c;
		}
		else{
			int l, r;
			cin>>l>>r; l--; r--;
			int cnt=0;
			rep(i, 26) if(bit[i].sum(l, r)>=1) cnt++;
			cout<<cnt<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 109620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int a,b,c;
	scanf("%d %d %d",&a ,&b, &c);

	if(a==b&&b==c){
		printf("1\n");
	}else if(a==b || b==c || c==a){
		printf("2\n");
	}else{
		printf("3\n");
	}

	return 0;
}


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

int H,W,Ans,top,stop[2010][2010];
bool g[2010][2010];

struct Point{
	int x,y;
	Point() {}
	Point(int x,int y):x(x),y(y) {}
}P[2010];

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,j;
	char c;
	scanf("%d%d",&H,&W);
	for (i=1;i<=H;i++)
	for (j=1;j<=W;j++)
	{
		c=getchar();
		while (c!='.'&&c!='#') c=getchar();
		g[i][j]=c=='#';
	}

	Ans=max(H,W);
	for (i=1;i<=H;i++)
	for (j=W;j>=2;j--)
		g[i][j]^=g[i][j-1];

	for (j=2;j<=W;j++)
	{
		int last[2];
		last[0]=last[1]=H+1;
		for (i=H;i>=1;i--)
		{
			stop[i][j]=last[g[i][j]^1];
			last[g[i][j]]=i;
		}
	}

	for (i=1;i<H;i++)
	{
		P[top=1]=Point(i,W+1);
		for (j=W;j>=2;j--)
		{
			while (P[top].x>=stop[i][j])
			{
				Ans=max(Ans,(P[top].x-i)*(P[top-1].y-j));
				top--;
			}
			P[++top]=Point(stop[i][j],j);
		}
		while (top)
			Ans=max(Ans,(P[top].x-i)*(P[top-1].y-j)),top--;
	}
	printf("%d\n",Ans);
}


Measured memory_bytes: 19968
//Malfurion_Drake
#include<bits/stdc++.h>
#define Maxn 100005
using namespace std;

int n,m,Pow[31];

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

/*template<typename Drake>
inline Drake max(Drake Cmp1,Drake Cmp2){
	return(Cmp1>Cmp2 ? Cmp1 : Cmp2);
}

template<typename Drake>
inline Drake min(Drake Cmp1,Drake Cmp2){
	return(Cmp1<Cmp2 ? Cmp1 : Cmp2);
}

void addedge(int u,int v){
	++tot;
	ver[tot]=v;
	Next[tot]=head[u];head[u]=tot;
}*/

void init(){
	
	read(n);read(m);
	
}

bool check(int num){
	int len=m/num;
	return(len>=n);
}

int main(){
	init();
	
	int mx=1;
	for(int i=1;i*i<=m;++i)
	if(m%i==0){
		if(check(i))
		mx=max(mx,i);
		if(check(m/i))
		mx=max(mx,m/i);
	}
	cout<<mx<<endl;
	return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++){
    cin >> d.at(i);
  }
  int t = 0;
  for (int i = 0; i < n; i++){
    for (int j = i+1; j < n; j++){
      t += d.at(i) * d.at(j);
    }
  }
  cout << t << endl;
}



Measured memory_bytes: 3632
N, K = map(int, input().split())
H = list(map(int, input().split()))
P = [0] + [-1] * (len(H)-1)

def minv(i, v):
  if i < len(H):
    cost = v()
    if P[i] < 0:
      P[i] = cost
    else:
      P[i] = min(P[i], cost)

for i in range(len(H)-1):
  for k in range(1, K+1):
    minv(i + k, lambda : P[i] + abs(H[i] - H[i+k]))

print(P[-1])

Measured memory_bytes: 53088
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<long long> v;
	int a;
	for (int i = 0; i < 3 * n; i++) {
		cin >> a;
		v.emplace_back(a);
	}
	sort(v.begin(), v.end(),greater<int>());
	long long ans = 0;
	for (int i = 1; i <=n; i++) {
		ans += v[i*2-1];
	}
	cout << ans << endl;
}

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

using namespace std;

int n;
int a[10004], b[10004];
long long c1, c2;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	c1 = c2 = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] < b[i]) {
			c1 += (b[i] - a[i])/2;
		}
		else {
			c2 += a[i] - b[i];
		}
	}
	if (c1 < c2) cout << "No"; else cout << "Yes";
}

Measured memory_bytes: 384
S = input()


def solve(s):
    buf = [1] * len(s)

    for i in range(len(buf) - 2):
        if s[i] == "R" and s[i + 1] == "R":
            buf[i+2] += buf[i]
            buf[i] = 0

    for i in range(len(buf) - 1, 1, -1):
        if s[i] == "L" and s[i - 1] == "L":
            buf[i-2] += buf[i]
            buf[i] = 0

    return " ".join(map(str, buf))


print(solve(S))


Measured memory_bytes: 84420
n, k = gets.split( " " ).map { |val| val.to_i }
w = []
maxW = sumW = 0
n.times {
	num = gets.to_i
	sumW += num
	w.push( num )
	maxW = num if maxW < num
}

minP = 0
if 1 == k
	minP = sumW
elsif n == k
	minP = maxW
else
	left = maxW
	right = 100000*10000
	while left <= right
		middle = ( left+right ).div( 2 )
		truckCnt = i = loadings = 0

		while i < n
			loadings += w[i]
			if middle < loadings
				truckCnt += 1
				break if k < truckCnt+1
				loadings = w[i]
			end
			i += 1
		end
		( minP = middle ) if truckCnt+1 <= k
		
		if k < truckCnt+1
			left = middle + 1		
		else
			right = middle - 1
		end
	end
end

puts( minP )

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


const int MAX_N = 1000000;
int N;
vector<long long> bit(MAX_N);

void init() {
	for (int i=0;i<MAX_N;i++) {
		bit[i] = 0LL;
	}
}

void add(int x, long long a) {
	for (int i=x;i<=N;i+=i&(-i)) {
		bit[i] += a;
	}
}

long long sum(int x) {
	long long tmp = 0LL;
	for (int i=x;i>0;i-=i&(-i)) {
		tmp += bit[i];
	}
	return tmp;
}

bool compare_by_b(vector<int> a, vector<int> b) {
    if(a[1] != b[1]){
        return a[1] < b[1];
    } else {
        return a[0] < b[0];
    }
}


int main() {
	int Q;
	cin >> N >> Q;
	vector<int> c(N);
	for (int i=0;i<N;i++) {
		cin >> c[i];
	}
	vector<vector<int>> l_r(Q);
	vector<long long> ans(Q);
	for (int i=0;i<Q;i++) {
		int l, r;
		cin >> l >> r;
		vector<int> vec = {l, r, i};
		l_r[i] = vec;
	}


	sort(l_r.begin(), l_r.end(), compare_by_b);
	init();

	vector<int> pre(N);
	for (int i=0;i<N;i++) {
		pre[i] = -1;
	}

	int index_lr = 0;
	for (int r=1;r<=N;r++) {
		add(r, 1);
		if (pre[c[r-1]-1] != -1) add(pre[c[r-1]-1], -1);
		pre[c[r-1]-1] = r;

		while (index_lr<Q && l_r[index_lr][1] == r) {
			long long val = sum(r)-sum(l_r[index_lr][0]-1);
			ans[l_r[index_lr][2]] = val;
			index_lr++;
		}
	}

	for (int i=0;i<Q;i++) {
		cout << ans[i] << endl;
	}
	// for (int i=0;i<Q;i++) {
		// cout << l_r[i][0] << " " << l_r[i][1] << " " << l_r[i][2] << endl;
	// }

}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

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

  int mi = 1e9;
  for (int i = 1; i <= n / 2; ++i) {
    int a = i;
    int b = n - i;

    string sa, sb;
    sa = to_string(a);
    sb = to_string(b);
    int sum = 0;
    for (char j : sa) {
      sum += (j - '0');
    }
    for (char j : sb) {
      sum += (j - '0');
    }
    mi = min(sum, mi);
  }
  p(mi);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int N = 2e5 + 10;
 
int n, m, k;
ll a[N], b[N];
 
int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1, x; i <= n; ++i) scanf("%d", &x), a[i] = a[i - 1] + x;
	for (int i = 1, x; i <= m; ++i) scanf("%d", &x), b[i] = b[i - 1] + x;
	
	int j = m;
	ll ans = 0;
	for (int i = 0; i <= n; ++i)
	{
		if (a[i] > k) break;
		while (a[i] + b[j] > k) j --;
		ans = max(ans, i + j + 0LL);
	}
	
	printf("%lld\n", ans);
	
	return 0;
} 

Measured memory_bytes: 6988
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,n,a) for(int i=n;i>a;i--)
#define mem0(x) memset(x,0,sizeof(x))
#define memff(x) memset(x,0xff,sizeof(x))
#define INF 100000000
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
int w,h,n;
int sw[15],sh[15];
char maze[1024][1024];
int d[1024][1024];
int dw[4]={0,1,0,-1},dh[4]={1,0,-1,0};
int BFS(int sw,int sh,int gw,int gh)
{
    queue<P> que;
    for(int i=1;i<=w;i++)
    {
        for(int j=1;j<=h;j++)
        {
            d[i][j]=INF;
        }
    }
    que.push(P(sw,sh));
    d[sw][sh]=0;
    while(que.size())
    {
        P p=que.front();
        que.pop();
        if(p.first==gw&&p.second==gh)break;
        for(int i=0;i<4;i++)
        {
            int nw=p.first+dw[i],nh=p.second+dh[i];
            if(1<=nw&&nw<=w&&1<=nh&&nh<=h&&maze[nw][nh]!='X'&&d[nw][nh]==INF)
            {
                que.push(P(nw,nh));
                d[nw][nh]=d[p.first][p.second]+1;
            }
        }
    }
    return d[gw][gh];
}
int main()
{
    //freopen("input.in","r",stdin);
    while(cin>>w>>h>>n)
    {
        int ans=0;
        for(int i=1;i<=w;i++)
        {
            for(int j=1;j<=h;j++)
            {
                cin>>maze[i][j];
                if(maze[i][j]=='S')
                {
                    sw[0]=i;sh[0]=j;
                }
            }
        }
        for(int i=1;i<=w;i++)
        {
            for(int j=1;j<=h;j++)
            {
                if(maze[i][j]>48&&maze[i][j]<58)
                {
                    sw[maze[i][j]-48]=i;
                    sh[maze[i][j]-48]=j;
                }
            }
        }
        for(int i=0;i<=n-1;i++)
        {
            ans+=BFS(sw[i],sh[i],sw[i+1],sh[i+1]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 6308
// ABC148B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;
	for (int i = 0; i < N; i++)
	{
		cout << S.at(i) << T.at(i);
	}
	cout << endl;
}

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

int N; long long A, B;
#define MAX_N 100000
long long S[MAX_N];
int FA[MAX_N], FB[MAX_N];
#define MOD 1000000007
long long X[MAX_N], Y[MAX_N];

void solve(int i, long long a, int fb[MAX_N],
  long long x[MAX_N], long long y[MAX_N]) {
  int j = upper_bound(S, S + N, S[i] - a) - S - 1;
  if(j < 0) x[i] = fb[i - 1] - fb[0] == i - 1;
  else if(j == i - 1) x[i] = (x[i - 1] + y[i - 1]) % MOD;
  else {
    if(fb[i - 1] - fb[j + 1] == (i - 1) - (j + 1)) {
      x[i] = y[j + 1];
    } else {
      x[i] = 0;
    }
  }
}
int main() {
  cin >> N >> A >> B;
  for(int i = 0; i < N; ++i) cin >> S[i];
  FA[0] = FB[0] = 0;
  for(int i = 1; i < N; ++i) {
    FA[i] = FA[i - 1] + (S[i] - S[i - 1] >= A);
    FB[i] = FB[i - 1] + (S[i] - S[i - 1] >= B);
  }
  X[0] = Y[0] = 1;
  for(int i = 1; i < N; ++i) {
    solve(i, A, FB, X, Y);
    solve(i, B, FA, Y, X);
  }
  cout << (X[N - 1] + Y[N - 1]) % MOD << endl;
  return 0;
}


Measured memory_bytes: 3328
def resolve():
    A = sorted([int(i) for i in input().split()])
    if max(A) * 3 % 2 == sum(A) % 2:
        print((max(A) * 3 - sum(A)) // 2)
    else:
        print(((max(A) + 1) * 3 - sum(A)) // 2)


resolve()


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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for (int i = s; i < (e); ++i)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define FILEIO                          \
    freopen("./input.txt", "r", stdin); \
    freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                               \
    for (                                                                       \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second;                                                       \
        debug("%s : %lld ms\n ", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T &x) { return x > 0 ? x : -x; }
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }

int main()
{
    FASTIO
#ifdef LOCAL
    FILEIO
#endif
    string n;
    cin >> n;
    forn(i, 0, n.length())
    {
        if (n[i] == '1')
        {
            n[i] = '9';
        }
        else if (n[i] == '9')
        {
            n[i] = '1';
        }
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = in.nextInt();
    }

    for (int i = 1; i < N; i++) {
      if (A[i - 1] < A[i]) {
        A[i]--;
      } else {
        if (A[i - 1] != A[i]) {
          System.out.println("No");
          return;
        }
      }
    }
    System.out.println("Yes");
  }
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

// A

const string YES = "";
const string NO  = "";

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

void solve() {

}

int main() {
  
  int L,R,c=0,d;
  
  cin >> L >> R >> d;
  REP(i,L,R+1) {
    if( i % d == 0 ) ++c;
  }
  cout << c<< endl;
  
  return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int len=0;

struct node
{
	int val,s0,s1,s2,delta;	
}a[2000000];

int n,ans[2000000];
string s;

void pushdown(int pos)
{
	if(a[pos].delta==0) return;
	a[pos].delta=0;
	a[a[pos].s0].delta^=1;
	swap(a[a[pos].s0].s1,a[a[pos].s0].s2);
	a[a[pos].s1].delta^=1;
	swap(a[a[pos].s1].s1,a[a[pos].s1].s2);
	a[a[pos].s2].delta^=1;
	swap(a[a[pos].s2].s1,a[a[pos].s2].s2);
}

int build(int lev,int cur)
{
	int pos=++len;
	if(lev==n)
	{
		a[pos].val=cur;
		a[pos].s0=a[pos].s1=a[pos].s2=a[pos].delta=0;
		return pos;
	}
	a[pos].val=a[pos].delta=0;
	a[pos].s0=build(lev+1,cur);
	a[pos].s1=build(lev+1,cur+pow(3,lev));
	a[pos].s2=build(lev+1,cur+pow(3,lev)*2);
	return pos;
}

void Rot(int pos)
{
	if(pos==0) return;
	pushdown(pos);
	int tmp=a[pos].s0;
	a[pos].s0=a[pos].s2;
	a[pos].s2=a[pos].s1;
	a[pos].s1=tmp;
	Rot(a[pos].s0);
}

void Swp()
{
	a[1].delta^=1;
	swap(a[1].s1,a[1].s2);
}

void getans(int pos,int lev,int cur)
{
	if(lev==n)
	{
		ans[a[pos].val]=cur;
		return;
	}
	pushdown(pos);
	getans(a[pos].s0,lev+1,cur);
	getans(a[pos].s1,lev+1,cur+pow(3,lev));
	getans(a[pos].s2,lev+1,cur+pow(3,lev)*2);
}

int main()
{
	cin>>n>>s;
	build(0,0);
	rep(i,s.size())
	{
		if(s[i]=='R') Rot(1);
		else Swp();
	}
	getans(1,0,0);
	rep(i,pow(3,n)) cout<<ans[i]<<' ';
	cout<<endl;
	return 0;
}

Measured memory_bytes: 21996
void main() {
	while(true) {
		auto ip = readAs!(int[]), H = ip[0], W = ip[1];
		if(H==0&&W==0) return;
		'#'.repeat(W).repeat(H).each!writeln;
		writeln;
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

int main(){
  
  int n;
  cin >>n;
  double a[n];
  double sum=0;
  
  for(int i=0; i<n; i++){
  	cin >> a[i];
    sum+=1/a[i]; 
  }
  
  cout <<setprecision(10)<< 1/sum << endl;

}

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

const int N = 205;
int n, ans;

int solve (int A, int B) {
	if(A%B==0) return A/B;
	return solve(A-(A%B+A/B)/(A/B+1)*(A/B+1), B);
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		int A, B;
		scanf("%d%d",&A,&B);
		ans ^= solve(A, B);
	}
	puts(ans ? "Takahashi" : "Aoki");
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, m;

struct Edge {
    int to, next;
} edges[maxn];

int tot = 1, head[maxn];

void addEdge(int u, int v) {
    edges[++tot] = {v, head[u]};
    head[u] = tot;
}

int dp[maxn];

int dfs(int u) {
    if (dp[u]) return dp[u];
    for (int i = head[u], v; i; i = edges[i].next) {
        v = edges[i].to;
        dp[u] = max(dp[u], dfs(v) + 1);
    }
    return dp[u];
}

int main() {
    int res = 0;
    scanf("%d%d", &n, &m);
    for (int i = 1, u, v; i <= m; i++) {
        scanf("%d%d", &u, &v);
        addEdge(u, v);
    }

    for (int i = 1; i <= n; i++) if (!dp[i]) dfs(i);

    for (int i = 1; i <= n; i++) res = max(res, dp[i]);

    printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 10240
/*
ID: karthik53
PROG: milk4
LANG: C++11

*/
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>

using namespace std;

//macros
typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;




#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 99999999
#define MOD 1000000007
#define MAX 15383
#define ITERS 100
#define pi 3.1415926
#define MAXN 50000
#define _gcd __gcd
#define f first
#define s second
vector<pair<int,int> > adj[100000];
int dist[100000];
bool vis[100000];
int main(){
    int k;
    cin >> k;
    REP(i,k){
        //build edges from this node
        for(int p = 0; p <= 9; p++){
            adj[i].PB(MP((10*i+p)%k,p));
        }
    }

    //dijkstra's algorithm to find shortest paths to every node
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
    REP(i,k) dist[i] = 1000000000;

    for(int p = 1;p<=9;p++){
        dist[p] = p;
        pq.push(MP(dist[p],p%k));
    }
    while(!pq.empty()){
        int tp = pq.top().second;
        pq.pop();
        if(vis[tp]) continue;
        vis[tp] = true;
        REP(i,SZ(adj[tp])){
            int to = adj[tp][i].first;
            int co = adj[tp][i].second;
            if(dist[tp] + co < dist[to]){
                dist[to] = dist[tp] + co;
                pq.push(MP(dist[to],to));
            }
        }
    }
    cout << dist[0] << endl;
}



Measured memory_bytes: 19316
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,x,y,x1,x2,flag1,flag2;
    string s;
    cin>>s;
    x=(s[0]-'0')*10+s[1]-'0';
    y=(s[2]-'0')*10+s[3]-'0';

    if((x>=1 && x<=12) && (y>=1 && y<=12))
    {
        cout<<"AMBIGUOUS"<<endl;
        return 0;
    }
    else if((x>=1 && x<=12))
    {
        cout<<"MMYY"<<endl;
    }
    else if((y>=1 && y<=12))
    {
        cout<<"YYMM"<<endl;
    }
    else
        cout<<"NA"<<endl;
}


Measured memory_bytes: 256
s=list(input())
t=list(input())

S=s+s
c=0

for i in range(len(s)):
  ch=0
  for j in range(len(s)):
    if S[i+j]==t[j]:
      ch+=1
  if ch==len(s):
    c+=1

if c>0:
  print('Yes')
  
else:
  print('No')



Measured memory_bytes: 9096
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 解説PDFを見て実装
#
# サーキットとは、辺を2回通らない経路のこと。要は一筆書きでできる経路。
#
# もし、あるグラフが、「全ての辺をちょうど 
# 1回ずつ使って3つのサーキットを作ることができる」条件を満たすとする。
#
# すると、グラフ全体は必ずオイラー路（すべての辺を使う閉路）でないといけない
# ことがわかる。
#
# オイラー路ができる必要十分条件は、全ての頂点の次数が偶数である
# ことを思い出す。これを満たしていなければ問題外。
# ここまでは気付きたかった。
#
# このあとはひたすら場合分け。解説PDFそのまま。
# 次数4の頂点が2個ある場合のコーナーケースに注意。
# またPythonの再起数の上限はデフォルトで1000なのに注意

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

sys.setrecursionlimit(1000000)

N, M = map(int, input().split())

edges = defaultdict(list)
edge_num = Counter()
for m in range(M):
    a, b = map(int, input().split())
    edge_num[a] += 1
    edge_num[b] += 1
    edges[a].append(b)
    edges[b].append(a)

def solve():
    values = edge_num.values()

    for v, num in edge_num.items():
        if num % 2 == 1:
            return False

    four = []
    for v, num in edge_num.items():
        if num >= 6:
            return True
        if num >= 4:
            four.append(v)

    if len(four) >= 3:
        return True
    if len(four) <= 1:
        return False

    # 一方の頂点からもう一方の頂点へのパスの数を数える
    v0 = four[0]
    v1 = four[1]
    path_num = 0

    def dfs(v, from_v):
        for child in edges[v]:
            if child == from_v:
                continue
            else:
                if child == v1:
                    return 1
                elif child == v0:
                    return 0
                else:
                    return dfs(child, v)

    for child in edges[v0]:
        path_num += dfs(child, v0)

    if path_num == 4:
        return False
    elif path_num == 2:
        return True

if solve():
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61780
#include<bits/stdc++.h>
using namespace std;
map<int,int> mapa;

int main(){
	int n,m;
	cin >> n >> m;
	for(int i = 1;i<=n;i++) mapa[i] = 0;
	int a,b;
	while(m--){
		cin >>a >> b;
		mapa[a]++;
		mapa[b]++;
	}
	
	for(auto it:mapa) cout<<it.second<<endl;
}

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

int main(void){
    int n, r;
    cin >> n;
    for(int i=1; i<=10; i++){
        if(n <= 111*i){
            r = 111*i;
            break;
        }
        if(i == 10) r = 1111;
    }
    
    cout << r << endl;
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, Q;

int main() {
    cin >> N >> Q;
    string S;
    cin >> S;

    vi c(N);
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        c[i] = cnt;
        if (S[i] == 'A' and S[i+1] == 'C') {
            cnt++;
        }
    }

    vi l(Q), r(Q);
    for (int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
    }

    for (int i = 0; i < Q; i++) {
        cout << c[r[i]-1] - c[l[i]-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <vector>

template <class Cost = int>
struct Edge {
    int from, to;
    Cost cost;
    Edge(int to = -1, int from = -1, Cost cost = 1)
        : from(from), to(to), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};
template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

const int INF = std::numeric_limits<int>::max() / 3;

using namespace std;


Graph<> tree;
int A, B;

// Aを求める
void dfs1(int v, int r) {
    int ch = 0;
    for (auto e : tree[v]) {
        if (e.to == r) continue;
        ++ch;
        dfs1(e.to, v);
    }
    A += ch / 2;
}

// パスの最大長がB以下になるようにしたとき、
// 親に送られるパスの最小値(無理ならINF)を返す
int dfs2(int v, int r) {
    vector<int> ch;
    for (auto e : tree[v]) {
        if (e.to == r) continue;
        ch.push_back(dfs2(e.to, v) + 1);
        if (ch.back() > B) return INF;
    }

    // ダミーを仕込んで奇数の場合に帰着させる
    if (ch.size() % 2 == 0) ch.push_back(0);

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

    int ok = ch.size(), ng = -1;
    // ok番目抜きで、和の最大値がB以下になるようマッチングできる
    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;

        bool judge = true;
        for (int l = 0, r = ch.size() - 1; l < r; ++l, --r) {
            if (l == mid) ++l;
            if (r == mid) --r;
            if (ch[l] + ch[r] > B) judge = false;
        }

        (judge ? ok : ng) = mid;
    }

    return (ok == ch.size() ? INF : ch[ok]);
}

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

    tree = Graph<>(N);
    for (int i = 0; i < N - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        tree[u].emplace_back(v);
        tree[v].emplace_back(u);
    }

    int r;
    for (r = 0; tree[r].size() > 1; ++r) {}

    A = 0;
    dfs1(r, -1);
    ++A;  // 根から出てくるパスを受け取る

    // Bを二分探索
    int ok = N, ng = -1;
    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;
        B = mid;
        (dfs2(r, -1) <= mid ? ok : ng) = mid;
    }

    cout << A << " " << ok << endl;
    return 0;
}


Measured memory_bytes: 15104
/* C Binary Search Tree III */

#include<stdio.h>
#include<stdlib.h>

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

struct Node *nil;
struct Node *root;
void init(){
  nil->key=-1;
  nil->parent=nil;
  nil->left=nil;
  nil->right=nil;
}

void Preorder(struct Node *u);
void Inorder(struct Node *u);

void TreeInsert(struct Node *T, struct Node *z);
struct Node *IterativeTreeSearch(struct Node *x, int k);
struct Node *TreeMinimum(struct Node *x);
struct Node *TreeSuccessor(struct Node *x);
struct Node *TreeDelete(struct Node *T, struct Node *z);

int main(){
  int n; /* command number */
  int k; 
  char com[6],c;
  int i;
  int j;
  struct Node *T;
  struct Node *z;
  struct Node *x;
  nil=malloc(sizeof(struct Node));
  init();
  /*scan*/
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&k);
      z=malloc(sizeof(struct Node));
      z->key=k;
      z->left=nil;
      z->right=nil;
      if(i==0)root=z;
      TreeInsert(T,z);
      T=z;
    }else if(com[0]=='p'){
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }else if(com[0]=='f'){
      scanf("%d",&k);
      x=IterativeTreeSearch(root,k);
      if(x==nil)printf("no\n");
      else printf("yes\n");
      //printf("find %d\n",k);
    }else{
      scanf("%d",&k);
      x=IterativeTreeSearch(root,k);
      TreeDelete(T,x);
    }
  }
  free(z);
  free(nil);
  return 0;
}
struct Node *TreeMinimum(struct Node *x){
  while(x->left!=nil){
    x=x->left;
  }
  return x;
}

struct Node *TreeSuccessor(struct Node *x){
  struct Node *y;
  if(x->right!=nil){
    return TreeMinimum(x->right);
  }
  y=x->parent;
  while(y!=nil&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

struct Node *TreeDelete(struct Node *T, struct Node *z){
  struct Node *x;
  struct Node *y;
  if(z->left==nil||z->right==nil){
    y=z;
  }else{
    y=TreeSuccessor(z);
  }
  if(y->left!=nil){
    x=y->left;
  }else{
    x=y->right;
  }

  if(x!=nil){
    x->parent=y->parent;
  }
  if(y->parent==nil){
    root=x;
  }else if(y==y->parent->left){
    y->parent->left=x;
  }else{
    y->parent->right=x;
  }
  if(y!=z){
    z->key=y->key;
  }
  return y;
}

struct Node *IterativeTreeSearch(struct Node *x, int k){
  while(x!=nil&&x->key!=k){
    if(k<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  return x;
}

void TreeInsert(struct Node *T, struct Node *z){
  struct Node *y;
  struct Node *x;
  y=nil;
  x=root;

  while(x!=nil){
    if(z==x)break;
    y=x;
    if(z->key<x->key){
      x=(x->left);
    }else{
      x=(x->right);
    }
  }
  z->parent=y;     
  if(y==nil){
    root=z; /* if T is empty */
  }else if(z->key<=y->key){
    y->left=z;
  }else{
    y->right=z;
  }
}

void Preorder(struct Node *u){
  if(u!=nil){
    printf(" %d",u->key);
    Preorder(u->left);
    Preorder(u->right);
  }
}

void Inorder(struct Node *u){
  if(u!=nil){
    Inorder(u->left);
    printf(" %d",u->key);
    Inorder(u->right);
  }
}

Measured memory_bytes: 9840
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
   //D問題
    int n;
    cin>>n;
    vector<ll> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    ll sum=0;
    for(int i=0;i<n-1;i++){
        if(v[i]<0){
            v[i]=-v[i];
            v[i+1]=-v[i+1];
        }
        sum+=v[i];
    }
    if(v[n-1]>=0){
        sum+=v[n-1];
        cout<<sum<<endl;
    }else{
        sum+=v[n-1];
        ll ans=sum;
        for(int i=n-2;i>=0;i--){
            v[i+1]=-v[i+1];
            sum+=2*v[i+1];
            v[i]=-v[i];
            sum+=2*v[i];
            ans=max(ans,sum);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <utility>
#include <valarray>
#include <climits>

using namespace std;

int main()
{
    int N, Ma, Mb;
    scanf("%d %d %d\n", &N, &Ma, &Mb);
    vector<tuple<int, int>> plus;
    vector<tuple<int, int>> minus;
    int plus_sum = 0;
    int minus_sum = 0;
    int result = INT_MAX;
    for (int i = 0; i < N; ++i){
        int ai, bi, ci;
        scanf("%d %d %d\n", &ai, &bi, &ci);
        int value = bi * Ma - ai * Mb;
        if (value > 0){
            plus.emplace_back(ci, value);
            plus_sum += value;
        }else if (value < 0){
            minus.emplace_back(ci, abs(value));
            minus_sum += abs(value);
        }else{
            result = min(ci, result);
        }
    }
    sort(plus.begin(), plus.end(), [](tuple<int, int>& l, tuple<int, int>& r){return get<1>(l) < get<1>(r);});
    sort(minus.begin(), minus.end(), [](tuple<int, int>& l, tuple<int, int>& r){return get<1>(l) < get<1>(r);});
    const int sum_max = min(plus_sum, minus_sum);
    vector<vector<int>> dp_plus(plus.size(), vector<int>(sum_max + 1, -1));
    vector<vector<int>> dp_minus(minus.size(), vector<int>(sum_max + 1, -1));
    function<int(int, int)> searchPlus = [&](int i, int sum){
        if (sum == 0) return 0;
        if (i >= plus.size() || sum < 0 || sum > sum_max) return INT_MAX;
        if (dp_plus[i][sum] != -1) return dp_plus[i][sum];
        int ret = INT_MAX;
        if (searchPlus(i + 1, sum) != INT_MAX) ret = min(searchPlus(i + 1, sum), ret);
        if (searchPlus(i + 1, sum - get<1>(plus[i])) != INT_MAX) ret = min(searchPlus(i + 1, sum - get<1>(plus[i])) + get<0>(plus[i]), ret);
        dp_plus[i][sum] = ret;
        return ret;
    };
    function<int(int, int)> searchMinus = [&](int i, int sum){
        if (sum == 0) return 0;
        if (i >= minus.size() || sum < 0 || sum > sum_max) return INT_MAX;
        if (dp_minus[i][sum] != -1) return dp_minus[i][sum];
        int ret = INT_MAX;
        if (searchMinus(i + 1, sum) != INT_MAX) ret = min(searchMinus(i + 1, sum), ret);
        if (searchMinus(i + 1, sum - get<1>(minus[i])) != INT_MAX) ret = min(searchMinus(i + 1, sum - get<1>(minus[i])) + get<0>(minus[i]), ret);
        dp_minus[i][sum] = ret;
        return ret;
    };
    for (int sum = 1; sum <= sum_max; ++sum){
        int cost_plus = searchPlus(0, sum);
        if (cost_plus == INT_MAX) continue;
        int cost_minus = searchMinus(0, sum);
        if (cost_minus == INT_MAX) continue;
        result = min(cost_plus + cost_minus, result);
    }
    if (result == INT_MAX){
        puts("-1");
    }else{
        printf("%d\n", result);
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'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'};
vector<char>AL(26);
AL = {'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'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	int X = N * 800;
	int Y = 200 * (N / 15);
	cout << X - Y << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))

ll ans,a,b,n;
ll d[100010];
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	rep(i,0,n)scanf("%lld",d+i);
	rep(i,0,n-1)ans+=min((d[i+1]-d[i])*a,b);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

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


class UnionFind:
    def __init__(self, node: int) -> None:
        self.n = node
        self.par = [i for i in range(self.n)]
        self.rank = [0 for i in range(self.n)]

    def find(self, x: int) -> int:
        if x == self.par[x]:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> bool:
        if self.isSame(x, y):
            # print("x and y has already united")
            return False

        rx = self.find(x)
        ry = self.find(y)

        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = self.par[ry]
        else:
            self.par[ry] = self.par[rx]

            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

        return True

    def isSame(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)


n, m = li()
p = list(li_())

uf = UnionFind(n)
for _ in range(m):
    x, y = li_()
    uf.unite(x, y)

for i in range(n):
    uf.find(i)

ans = 0
for i, pi in enumerate(p):
    if uf.isSame(i, pi):
        ans += 1

print(ans)

Measured memory_bytes: 13876
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n,m,i,c[100005],a,b,v,k,t[100005];
set<int> g[100005];
vector<int>first_half;
vector<int>second_half;
vector<int>total;
int par[209],group[209];
int arra[150000];
vector<ll>points;
map<char,ll>vis_c;
map<string,ll>nibo;
vector<ll>req;
vector<ll>instru;
vector< pair <ll,ll> > vect;
map<ll,ll>solve;
vector<ll>a5;
map<ll,ll>vis;
map<ll,ll>check;
int main()
{
  ll i,j,k,l,p,q,r,s,t,u,v,w,x=0,y,z,n,m;
  cin>>n;
  //a5.push_back()
  vis[0]=0;
  check[0]=1;
  a5.push_back(0);
  for(i=1;i<=1000;i++)
  {
     p=i;
     //a5.push_back(p);
     for(j=1;j<=4;j++)
     {
       p=p*i;	
     }
     vis[p]=i;
     vis[-p]=-i;
     check[p]=1;
     check[-p]=1;
     a5.push_back(p);	
  }
  j=0;
  while(1)
  {
      v=a5[j]-n;
      if(check[v]==1)
      {
         cout<<j<<" "<<vis[v];
         return 0;	
      }
      j++;	
  }
  
}

Measured memory_bytes: 8520