akhauriyash/Code-Regression huggingface dataset:
N = int(input())
C = list(input())
import copy
D = []
flag = 0
ans = 0
keisan = 0

for p in range(N):
    if C[p] == "R":
        D += ["0"]
    else:
        D += ["1"]



def change(x,y):
    global ans
    hoge = copy.deepcopy(D[x])
    D[x] = D[y]
    D[y] = hoge
    ans += 1

def color(x):
    global ans
    ans += 1
    if D[x] == "0":
        D[x] = "1"
    elif D[x] == "1":
        D[x] = "0"

zero = D.count("0")
ichi = D.count("1")

for p in range(zero):
    if D[p] == "1":
        ans += 1


"""
while flag == 0:

    for r in range(N):
        if int("".join(D),2) == 2**r-1:
            flag = 1

    if flag == 0:
        for q in range(N):
            if D[q] == "1":
                for s in range(N):
                    keisan += 1
                    if D[N-s-1] =="0" :
                        if q < N-s-1:
                            change(q,N-s-1)
                        break
            else:
                continue
            break
"""
print(ans)



Measured memory_bytes: 12664
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    string s;cin>>s;
    int ans=0,sum=0;
    for(int i=0;i<3;++i){
        if(s[i]=='R')sum++;
        else sum=0;
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int N,M,cnt;
VP E;
int V;
int cost[50][50];
int d[50];
bool used[50];
void dijkstra(int s){
  fill(d,d+V,INF);
  fill(used,used+V,false);
  d[s]=0;
  while(1){
    int v=-1;
    FOR(u,0,V){
      if(!used[u]&&(v==-1||d[u]<d[v])){
      v=u;
      }
    }
    if(v==-1){
      break;
    }
    used[v]=true;
    FOR(u,0,V){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }
}

int main(){
  cin>>N>>M;
  FOR(i,0,N){
    FOR(j,0,N){
      cost[i][j]=INF;
    }
  }
  V=N;
  FOR(i,0,M){
    int A,B;
    cin>>A>>B;
    A--;
    B--;
    E.PB(MA(A,B));
    cost[A][B]=1;
    cost[B][A]=1;
  }
  for(VP::iterator it=E.begin();it<E.end();it++){
    PA p=*it;
    cost[p.first][p.second]=INF;
    dijkstra(p.first);
    if(d[p.second]==INF){
      cnt++;
    }
    cost[p.first][p.second]=1;
  }
  cout<<cnt<<endl;
  return 0;
}


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

using ll = long long;

using namespace std;

int main() {
    char a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    cout << string(b - '0', a) << '\n';
    return 0;
}

Measured memory_bytes: 256
/*
P135
AOJ 0005 GCD and LCM
*/

#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
#include <cmath>

using namespace std;

int gcd(int a, int b)
{
    while(b){
        int c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main()
{
    int a, b;
    long long mul;
    while(cin>>a>>b){
        mul = a * (long long)b;
        int g = gcd(a, b);
        cout << g << " " << mul / g << endl;
    }
}

Measured memory_bytes: 1160
from collections import Counter
N = int(input())
S = input()
c = Counter(S)
ans = c['R']*c['G']*c['B']
for i in range(N):
  for j in range(i+1,N):
    k = j-i+j
    if k>N-1:
      continue
    if S[i]!=S[j] and S[j]!=S[k] and S[i]!= S[k]:
      ans -= 1
print(ans)


Measured memory_bytes: 68676
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>

using namespace std;

int main() {
	string s;
	int64_t k;
	cin >> s >> k;
	k--;
	for (int i = 0; i <= k; ++i) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
		else if (i == k) {
			cout << s[i] << endl;
			return 0;
		}
	}
}

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

int main(){
  int A, B, C, D;
  int sum = 0;
  cin >> A >> B >> C >> D;
  if(A>B) sum += B;
  else sum += A;
  if(C>D) sum += D;
  else sum += C;
  cout << sum << endl;
  return 0;
}





Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	REP(i,n){
		cin >> p[i];
	}
	
	int ans = 0;
	int tmp;
	REP(i,n){
		if(p[i]==i+1){
			ans++;
			if(i!=n-1){
				tmp = p[i];
				p[i] = p[i+1];
				p[i+1] = tmp;
			}else{
				tmp = p[i];
				p[i] = p[i-1];
				p[i-1] = tmp;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N=2e5+5;
int n,C; 
vector<ii> v[N];
int f[N];
int main()
{
	cin>>n>>C;
	for(int i=1;i<=n;i++)
	{
		int s,t,c;
		scanf("%d%d%d",&s,&t,&c);
		v[c].push_back(ii(s,t));	
	}
	for(int i=1;i<=C;i++)
		sort(v[i].begin(),v[i].end());
	for(int i=1;i<=C;i++)
	{
		int le,rg;
		if(v[i].size()==0)
			continue;
		for(int j=0;j<v[i].size();j++)
		{
			if(j==0)
			{
				le=v[i][j].first;
				rg=v[i][j].second;	
				continue;
			}			
			if(rg==v[i][j].first)
			{
				rg=v[i][j].second;
				continue;
			}
			f[le]++;
			f[rg+1]--;
			le=v[i][j].first;
			rg=v[i][j].second;
		}
		f[le]++,f[rg+1]--;
	}
	int mx=0;
	for(int i=0;i<N;i++)
		f[i]+=f[i-1],mx=max(mx,f[i]);
	cout<<mx<<endl;
	return 0;	
} 

Measured memory_bytes: 7292
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n;
    R(n);
    VI d(n);
    REP(i,n)R(d[i]);
    SORT_UNIQUE(d);
    W(SZ(d)==n?"YES":"NO");
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;



int main(){
    int n;
    
    cin >> n;
    int d = n%10;
    if (d == 2 || d == 4 || d == 5 || d == 7 || d == 9){
        cout << "hon";
    }
    else if (d==1 || d == 6 || d == 8 || d == 0){
        cout << "pon";
    }
    else{
        cout << "bon";
    }
    
}
















Measured memory_bytes: 3592
#include <stdio.h>

int main()
{
    int x,y,n,k;
    int mul,r,z,m;
    scanf("%d%d%d%d",&n,&k,&x,&y);
    mul=n-k;

   if(mul>=0)
   { z=x*k;
    r=y*mul;
    m=r+z;
    printf("%d\n",m);
    }
    else
    {

     z=x*n;
    printf("%d\n",z);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
signed main()
{
  int x=0,y=0,z=0,n=0,m=0,w=0;
  char a;
  std::vector<int> v={0,0,0,0};
  std::cin >> x;
  rep(i,x){
    std::cin >> a;
    if(a=='G')v[0]++;
    else if(a=='W')v[1]++;
    else if(a=='P')v[2]++;
    else v[3]++;
  }
  sort(all(v));
  if(v[0]==0)std::cout << "Three" << '\n';
  else std::cout << "Four" << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;
vector<int> res(26, 0);

int main(){
    // cout << (int)'A' << endl; //65
    // cout << (int)'Z' << endl; //90
    // cout << (int)'a' << endl; //97
    // cout << (int)'z' << endl; //122
    // cout << (int)'.' << endl; //46

    while(true){
        string S;
        getline(cin, S);
        if(S == "") break;

        for(int i=0;i<S.size();i++){
            int tmp = (int)S[i];
            if(97<=tmp && tmp<=122){
                ++res[tmp-97];
            }
            else if(65<=tmp && tmp<=122){
                ++res[tmp-65];
            }
        }
    }

    for(int i=0;i<26;i++){
        cout << (char)(i+97) << " : " << res[i] << endl;
    }
}


Measured memory_bytes: 3180
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=310;
const long long mod=1e9+7;
int n,m,id[M][M];
long long f[M][M][M],ans;
struct qury
{
	int l,r,mx;
}q[M];
bool check(int pr,int pg,int pb)
{
//	cout<<pr<<" "<<pg<<" "<<pb<<endl;
	int cnt=0,xx=max(pr,max(pg,pb));
	for(int i=1;i<=id[xx][0];i++)
	{
		cnt=0;
		int ii=id[xx][i];
		if(pr>=q[ii].l)	cnt++;
		if(pg>=q[ii].l) cnt++;
		if(pb>=q[ii].l)	cnt++;
		if(cnt!=q[ii].mx)
		{
			f[pr][pg][pb]=0;
			return 0;
		}
	}
//	cout<<"Yesss"<<endl;
	return 1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)	
		scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].mx),id[q[i].r][++id[q[i].r][0]]=i;
	f[0][0][0]=1;
	for(int i=0;i<=n;i++)	
		for(int j=0;j<=n;j++)
			for(int k=0;k<=n;k++)
			{
				if(f[i][j][k]==0)
					continue;
				if(check(i,j,k)==0)
					continue;
				int nw=max(i,max(j,k))+1;
				if(nw==n+1)
					(ans+=f[i][j][k])%=mod;
				(f[nw][j][k]+=f[i][j][k])%=mod;
				(f[i][nw][k]+=f[i][j][k])%=mod;
				(f[i][j][nw]+=f[i][j][k])%=mod;
			}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 227840
#include<iostream>
#include<string>
#include<queue>
using namespace std;
using I=long long;
#define rep(i,n) for(I i=0;i<n;++i)
int main(){
  I n,m;
  cin>>n>>m;
  vector<I> a(n);
  rep(i,n)cin>>a[i];
  priority_queue<I> que(a.begin(),a.end());
  rep(i,m){
    I t=que.top();
    que.pop();
    que.push(t/2);
  }
  I ans=0;
  while(que.size()){
    ans+=que.top();
    que.pop();
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){fast;
	ll i,n,x,j;cin>>n>>x;vi w(n),v(n);vvi d(n+1,vi(mxn+5,1e18));
	for(i=0;i<n;i++) cin>>w[i]>>v[i];
	for(i=0;i<=n;i++) d[i][0]=0;
	for(i=1;i<=n;i++){
		for(j=0;j<=mxn+4;j++){
			d[i][j]=min(d[i-1][j],d[i][j]);
			if(j+v[i-1]<=mxn) d[i][j+v[i-1]]=min(d[i][j+v[i-1]],d[i-1][j]+w[i-1]);
		}
	}for(j=mxn+4;j>=0;j--) if(d[n][j]<=x) return cout<<j<<endl,0;
//	for(i=1;i<=n;i++){
//		for(j=0;j<=mxn;j++){
//			if(d[i][j]-1e18) cout<<j<<" "<<d[i][j]<<endl;
//		}cout<<endl;
//	}
}


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

typedef long long ll;
ll n, m;
ll Sum, x;

int main(){
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		cin >> x;
		Sum += x;
	}
	if(Sum <= n) cout << n - Sum;
	else cout << -1;
	return 0;
}

Measured memory_bytes: 3636
input_list = list(map(int, input().split(" ")))
w = input_list[0]
h = input_list[1]
x = input_list[2]
y = input_list[3]
r = input_list[4]

x_max = x + r
x_min = x - r
y_max = y + r
y_min = y - r

if x_max <= w and y_max <= h and x_min >= 0 and y_min >= 0 :
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m,k;
cin>>n>>m>>k;
int a[n],b[m];
vector<long long> sma(n),smb(m);
int ans=0;

for(int i=0;i<n;i++)
{cin>>a[i];
if(i==0)
sma[i]=a[i];
else sma[i]=sma[i-1]+a[i];
if(sma[i]<=k)
ans=max(ans,i+1);
}
for(int i=0;i<m;i++)
{cin>>b[i];
if(i==0)
smb[i]=b[i];
else smb[i]=smb[i-1]+b[i];
if(smb[i]<=k)
ans=max(ans,i+1);
}
for(int i=0;i<n;i++)
{
    if(k-sma[i]>0){
       // cout<<k-sma[i]<<endl;
    int ind=upper_bound(smb.begin(),smb.end(),k-sma[i])-smb.begin();
      ind--;
    
     if(ind>=0&&k-sma[i]>=smb[ind])
    {
   // cout<<i<<" "<<ind<<endl;

        ans=max(i+ind+2,ans);
    }}
}
cout<<ans;
return 0;

}


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

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


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long N;
main()
{
	cin>>N;
	vector<long>d;
	for(long i=1;i*i<=N;i++)
	{
		if(N%i==0)
		{
			d.push_back(i);
			if(N/i!=i)d.push_back(N/i);
		}
	}
	long ans=0;
	for(int i=0;i<d.size();i++)
	{
		long M=d[i];
		if(M==1)continue;
		M--;
		if(N/M==N%M)ans+=M;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main{
    public static void main(String []args)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b =sc.nextInt();
        int c =sc.nextInt();
        int x3=Math.abs(a-b);
        int x1= Math.abs(a-c);
        int x2= Math.abs(b-c);
        int total=x1+x2+x3;
        total = Math.abs(total-(Math.max(x3,Math.max(x2,x1))));
        System.out.println(total);

    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll f(ll x,ll k,ll d){
	if(k%2==0)
		return abs(x);
	else
		return min(abs(x-d),abs(x+d));
}
void solve(){
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll res=f(x,k,d);
	ll t=x/d;
	if(t>=k)
		res=min(res,abs(x-k*d));
	else
		res=min(res,f(x-t*d,k-t,d));
	if(t+1>=k)
		res=min(res,abs(x-k*d));
	else
		res=min(res,f(x-(t+1)*d,k-(t+1),d));
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

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

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

	int N;
	int i,j;
	int tmp;
	ll min=1000000000;
	int place;
	ll answer;
	ll counter=0;
	double ave;
	vector<int> given;

	cin >> N;

	for(i=0;i<N;i++){
		cin >> tmp;
		given.push_back(tmp);
	}

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

/*
	place=(given[0]+given[N-1])/2;
		
	for(i=0;i<N;i++){
		counter+=(ll)pow(abs(given[i]-place),2);
	}
*/
	for(place=1;place<=given[N-1];place++){
		counter=0;
		for(i=0;i<N;i++){
			counter+=(ll)pow(abs(given[i]-place),2);
		}
		if(min>counter) min=counter;
	}

	answer=min;
	cout << answer << endl;

	return 0;
}



Measured memory_bytes: 256
s = input()

s_a = int(s[:2])
s_b = int(s[2:])

if s_a >= 1 and s_a <=12 and s_b >= 1 and s_b <=12:
  ans = "AMBIGUOUS"
elif (s_a > 12 or s_a == 0) and s_b >= 1 and s_b <=12:
  ans = "YYMM"
elif (s_b > 12 or s_b == 0) and s_a >= 1 and s_a <=12:
  ans = "MMYY"
else:
  ans = "NA"

print(ans)

Measured memory_bytes: 9132
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;

	vector<int> vec(n);
	string ans = "APPROVED";
	rep(i, n)
	{
		cin >> vec[i];
		if (vec[i] % 2 == 0)
		{
			if (!(vec[i] % 3 == 0 || vec[i] % 5 == 0))
			{
				ans = "DENIED";
			}
		}
	}
	cout << ans << '\n';

	return 0;
}


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

int main(){
	bool a[100001]{};
	int n;
	cin >> n;
	while(n--){
		int l, r;
		cin >> l >> r;
		for(int i = l; i <= r; i++) a[i] = true;
	}
	int ans = 0;
	for(int i = 0; i < 100001; i++) if(a[i]) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A > B)
    {
        if (B < C and C < A)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    if (A < B)
    {
        if (A < C and C < B)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import collections
mod=998244353
ans=1
n=int(input())
d=list(map(int,input().split()))
c=collections.Counter(d)
num=[]
for j in range(len(c)):
  num.append(c[j])
if d[0]!=0 or num[0]!=1:
  print(0)
else:
  for i in range(1,len(num)-1):
    ans*=(num[i]**num[i+1])%mod
  print(ans%mod)

Measured memory_bytes: 66740
#include<stdio.h>

#define CNST_DAY 365
#define NUM_CONTEST 26

int main(void){

    int i,j,k,d,n;
    int D,c[NUM_CONTEST+1]={},s[CNST_DAY+1][NUM_CONTEST+1]={},last[NUM_CONTEST+1]={},t[CNST_DAY+1]={};
    long v[CNST_DAY+1]={};

    int smax[CNST_DAY+1]={},maxcon[CNST_DAY+1]={};

    //入力
    (void)scanf("%d",&D);
    for(d=1;d<=NUM_CONTEST;d++){
        (void)scanf("%d",&c[d]);
    }
    for(d=1;d<=D;d++){
        for(i=1;i<=NUM_CONTEST;i++){
            (void)scanf("%d",&s[d][i]);
        }
    }
    
    //スコア計算
    for(d=1;d<=D;d++){
        smax[d]=s[d][1];
        maxcon[d]=1;
        for(i=2;i<=NUM_CONTEST;i++){
            if(s[d][i]>smax[d]){
                smax[d]=s[d][i];
                maxcon[d]=i;
            }
        }
    }
    for(d=1;d<=D;d++){
        //その日一番大きい満足度が得られるコンテストを開く(満足度の低下を無視したもの)
        t[d]=maxcon[d];

        //開催するコンテストt[d]を決めた後
        last[t[d]]=d;
        v[d]=v[d-1]+s[d][t[d]];
        for(i=1;i<=NUM_CONTEST;i++){
            v[d]-=c[i]*(d-last[i]);
        }
    }

    //出力
    for(d=1;d<=D;d++){
        //printf("%ld\n",v[d]);
        printf("%d\n",t[d]);
    }

    return 0;
}

Measured memory_bytes: 1776
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define INF (1<<29)

struct P{
  int v,time,cur;
  P(int a, int b, int c){v=a;time=b;cur=c;}
  bool operator<(const P& a)const{ return v < a.v; }
  bool operator>(const P& a)const{ return v > a.v; }
};

struct Edge{
  int to,cost;
  Edge(int t, int c){to=t;cost=c;}
};

int N,M,L,K,A,H;
vector<Edge>G[128];
int dist[128][128];
int frez[128];

void dijkstra(){
  rep(i,M+1) fill(dist[i], dist[i] + N, INF);
  priority_queue<P, vector<P>, greater<P> >q;
  dist[M][A]=0;
  q.push(P(0,M,A));
  
  while(!q.empty()){
    P p = q.top(); q.pop();
    if(p.v > dist[p.time][p.cur]) continue;
    rep(i,G[p.cur].size()){
      Edge e = G[p.cur][i];
      if(p.time-e.cost >= 0 && dist[p.time-e.cost][e.to] > dist[p.time][p.cur] + e.cost){
	int tmp = dist[p.time][p.cur] + e.cost;
	dist[p.time-e.cost][e.to] = tmp ;
	q.push(P(dist[p.time-e.cost][e.to], p.time-e.cost, e.to));
      }

      if(frez[p.cur]){
	for(int r=1;r<=M-p.time;r++){
	  if(p.time-e.cost+r >= 0 && dist[p.time-e.cost+r][e.to] > dist[p.time][p.cur] + e.cost + r){
	    dist[p.time-e.cost+r][e.to] = dist[p.time][p.cur] + e.cost + r;
	    q.push(P(dist[p.time-e.cost+r][e.to], p.time-e.cost+r, e.to));
	  }
	}
      }
    }
  }
}

int main(){
  while(cin >> N >> M >> L >> K >> A >> H, N+M+L+K+A+H){
    memset(frez,0,sizeof(frez));
    rep(i,128) G[i].clear();
    frez[A] = frez[H] = 1;
    rep(i,L){
      int x; cin >> x;
      frez[x] = 1;
    }
    rep(i,K){
      int x,y,t; cin >> x >> y >> t;
      G[x].push_back(Edge(y,t));
      G[y].push_back(Edge(x,t));
    }

    dijkstra();
    int res = INF;
    rep(i, M+1)  res = min(res, dist[i][H]);
    if(res==INF) cout << "Help!\n";
    else cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1588
s = gets.chomp
cnt = 0
num = Array.new(s.length, 0)

(0..(s.length - 2)).each do |i|
  cnt += 1 if s[i] == 'R'
  if s[i] + s[i+1] == 'RL'
    if cnt > 0
      if cnt.even?
        tmp = cnt / 2
        num[i] += tmp
        num[i+1] += tmp
      else
        if cnt == 1
          num[i] += 1
        else
          tmp = cnt / 2
          num[i] += tmp + 1
          num[i+1] += tmp
        end
      end
    end
  cnt = 0
  end
end

(s.length - 1).downto(1).each do |i|
  cnt += 1 if s[i] == 'L'
  if s[i-1] + s[i] == 'RL'
    if cnt > 0
      if cnt.even?
        tmp = cnt / 2
        num[i] += tmp
        num[i-1] += tmp
      else
        if cnt == 1
          num[i] += 1
        else
          tmp = cnt / 2
          num[i] += tmp + 1
          num[i-1] += tmp
        end
      end
    end
  cnt = 0
  end
end

puts num.join(' ')

Measured memory_bytes: 3196
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc106_ab
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();
            int a = input[0];
            int b = input[1];
            WriteLine(a*b-a-b+1);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n, m;
  cin >> n >> m;
  vi a(m);
  rep(i, m) cin >> a[i];

  vi dp(n+1);
  dp[0] = 1;
  
  a.push_back(n+1);

  const int MOD = 1000000007;
  int cnt = 0;
  rep(i, n) { 
    if (i+1 == a[cnt]) {
      cnt++;
      continue;
    }
    if (i == 0) {
      dp[i+1] = 1;
    } else {
      dp[i+1] = (dp[i] + dp[i-1]) % MOD;
    }
  }
  cout << dp[n] << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
  	cin >> vec.at(i);
  }
  
  int now = 0;
  for(int j=0; j < N; j++) {
    //cout << now;
    if(now == 1){
    	cout << j;
      	break;
    }
    else if (j == N-1){
    	cout << -1;
    }
    
    now = vec.at(now)-1;
  }
}

Measured memory_bytes: 3768
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


bool check(string s){
    string tar("AKIHABARA");
    const int n = tar.size();
    REP(i, 1 << n){
        string t = "";
        REP(j, n){
            if((tar[j] != 'A') || ((i >> j) & 1))
                t += tar[j];
        }
        if(s == t) return true;
    }
    return false;
}

int main(){
    string S; cin >> S;
    cout << (check(S) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
/*input
6
1 2
2 3
3 4
3 5
3 6

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
vector<int> edge[maxn];
bool vis[maxn];
int a[maxn],b[maxn];
void go(int u,int d){
	vis[u]=1;
	a[u]=d;
	for(int v:edge[u]) if(!vis[v]){
		go(v,d+1);
	}
}
void dfs(int u,int d){
	vis[u]=1;
	b[u]=d;
	for(int v:edge[u]) if(!vis[v]){
		dfs(v,d+1);
	}
}

int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n-1){
		int u,v;
		cin>>u>>v;
		u--;v--;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	go(n-1,0);
	REP(i,n) vis[i]=0;
	dfs(0,0);
	int cnt=0;
	REP(i,n) if(a[i]>=b[i]) cnt++;
	if(cnt>n-cnt) cout<<"Fennec\n";
	else cout<<"Snuke\n";
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int x, a, b;
    cin >> x >> a >> b;
    int n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        if (s == "nobiro")x = max(x + a, 0);
        else if (s == "tidime")x = max(x + b, 0);
        else x = 0;
    }
    cout << x << "\n";
}



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

using namespace std;

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

    int N,M; cin>>N>>M;
    vector<unsigned int> masks(M, 0);
    for (int i = 0; i < M; i++) {
        int k; cin>>k;
        while (k--) {
            int v; cin>>v;
            masks[i] |= 1u<<(v-1);
        }
    }
    vector<bool> p(M);
    for (int i = 0; i < M; i++) {
        int b; cin>>b;
        p[i] = (bool)b;
    }

    int ans = 0;
    for (unsigned int x = 0; x < 1u<<N; x++) {
        auto check = [&](unsigned int m, bool p) {
            auto t = x & m;
            bool c = 0;
            while (t) {
                c ^= t&1;
                t>>=1;
            }
            return c == p;
        };
        int sum = 0;
        for (int i = 0; i < M; i++) {
            sum += check(masks[i], p[i]);
        }
        if (sum == M)
            ans++;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String p = sc.next();
		String c;
		int flag = 0;
		
		for(int i = 0; i < s.length(); i++) {
			if(i + p.length() <= s.length()){
				c = s.substring(i, p.length() + i);
			} else {
				c = s.substring(i, s.length()) + s.substring(0, p.length() - (s.length() - i));
			}
			
			if(c.equals(p)) {
				flag = 1;
				break;
			}
		}
		
		if(flag == 1) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const double eps = 1e-9;

inline int dcmp(double x){if(-eps<x && x<eps)return 0;return x>0?1:-1;}

struct points
{
	double x,y;
	points(double _x=0,double _y=0){x=_x,y=_y;}

	inline friend points operator + (points a,points b){return points(a.x+b.x,a.y+b.y);}
	inline friend points operator - (points a,points b){return points(a.x-b.x,a.y-b.y);}
	inline friend points operator * (points a,double b){return points(a.x*b,a.y*b);}
	inline friend points operator / (points a,double b){return points(a.x/b,a.y/b);}

	void takein(){x=ty(),y=ty();}
	void print(char ends='\n'){printf("%.12lf %.12lf",x,y),putchar(ends);}
};

inline double dox(points a,points b){return a.x*b.x+a.y*b.y;}
inline double cox(points a,points b){return a.x*b.y-a.y*b.x;}
inline double length(points a){return sqrt(dox(a,a));}

points p1,p2,pd;

void finder()
{
	points p;
	p.takein();

	double dis=dox(p-p1,pd-p1);
	points tar=p1+(pd-p1)*dis;
	tar.print();
}

int main()
{
	p1.takein(),p2.takein();
	pd=p1+(p2-p1)/(length(p2-p1));
	
	int q=ty();
	while(q--)finder();

	return 0;
}



Measured memory_bytes: 3240
n, c, k = map(int, input().split())
ts = [int(input()) for _ in range(n)]
ts = sorted(ts)

cnt = 0
rider = 0
limit = -1
for t in ts:
    if (rider == c) or not(t <= limit <= (t + k)):
        cnt += 1
        limit = (t + k)
        rider = 1
    else:
        rider += 1

print(cnt)

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

using namespace std;

int n,x[300050],L,t[300050];
int l[300050],r[300050];
bool ing[300050];

int main()
{
	scanf("%d%d",&n,&L);
	for(int i = 1;i <= n; ++ i)
		scanf("%d",&x[i]);
	long long as = 2 * L;
	for(int i = 1;i <= n; ++ i)
	{
		scanf("%d",&t[i]);
		as += t[i] / (L * 2) * (L * 2);
		t[i] %= (L * 2);
		if(!t[i])
		{
			ing[i] = 1,as -= 2 * L;
			continue;
		}
		l[i] = 2 * x[i] >= t[i];
		r[i] = 2 * (L - x[i]) >= t[i];
		if(!l[i] && !r[i])
			ing[i] = 1;
	}
	as += n * 1ll * 2 * L;
	as -= r[n] * 2 * L;
	int cur = 0,cn = 0;
	for(int i = 1;i < n; ++ i)
	{
		if(i == n - 1 && ing[i])
		{
			cn += cur; cur = 0;
			for(int j = n - 1;j >= i + 1; -- j)
			{
				if(ing[j]) continue;
				if(!l[j]) break;
				if(r[j]) cur ++;
				else if(cur) cur --,as -= 2 * L;
			}
			cn += cur; cn >>= 1; as -= cn * 2ll * L;
			break;
		}
		if(ing[i]) continue;
		if(!r[i])
		{
			cn += cur; cur = 0;
			for(int j = n - 1;j >= i; -- j)
			{
				if(ing[j]) continue;
				if(!l[j]) break;
				if(r[j]) cur ++;
				else if(cur) cur --,as -= 2 * L;
			}
			cn += cur; cn >>= 1; as -= cn * 2ll * L;
			break;
		}
		if(l[i]) cur ++;
		else if(cur) cur --,as -= 2 * L;
		if(i == n - 1)
		{
			cn += cur; cur = 0;
			for(int j = n - 1;j >= i + 1; -- j)
			{
				if(ing[j]) continue;
				if(!l[j]) break;
				if(r[j]) cur ++;
				else if(cur) cur --,as -= 2 * L;
			}
			cn += cur; cn >>= 1; as -= cn * 2ll * L;
			break;
		}
	}
	printf("%lld\n",as);
}

Measured memory_bytes: 8740
import std.stdio;
import std.conv;
import std.string;

void main()
{
    int[] input = readln.split.to!(int[]);
    int sx = input[0];
    int sy = input[1];
    int tx = input[2];
    int ty = input[3];
    char[] ans;

    foreach (i; 0..(ty - sy))
        ans ~= 'U';
    foreach (i; 0..(tx - sx))
        ans ~= 'R';
    foreach (i; 0..(ty - sy))
        ans ~= 'D';
    foreach (i; 0..(tx - sx))
        ans ~= 'L';

    ans ~= 'L';
    foreach (i; 0..(ty - sy + 1))
        ans ~= 'U';
    foreach (i; 0..(tx - sx + 1))
        ans ~= 'R';
    ans ~= 'D';
    ans ~= 'R';
    foreach (i; 0..(ty - sy + 1))
        ans ~= 'D';
    foreach (i; 0..(tx - sx + 1))
        ans ~= 'L';
    ans ~= 'U';

    ans.writeln;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, ans = 1000000000;
	cin >> nn;
	vector<int64> ww(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> ww[ii];
	}
	for(int64 ii = 1;ii < nn;ii++)
	{
		ww[ii] += ww[ii - 1];
	}
	for(int64 ii = 0;ii < nn - 1;ii++)
	{
		ans = min(ans, abs(ww[nn - 1] - 2 * ww[ii]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env perl
use strict;
use warnings;

my $line1 = <STDIN>;
my ($n, $x) = split(/ /, $line1);
my $line2 = <STDIN>;
my @long = split(/ /, $line2);

my $distance;
for (my $i = 1; $i <= $n + 1; $i++) {
    if ($i == 1) {
        $distance = 0;
    }
    else {
        $distance += $long[($i - 1) - 1];
    }

    if ($distance > $x) {
        print($i - 1);
        last;
    }
    elsif ($i == $n + 1) {
        print $i;
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,n,m,i,j;
    vector<long long int>v;
    map<long long int,long long int>mp;
    set<long long int>s;
    string str;
    cin>>n>>a>>b;
    int blb = 0;
    for(i = a;i <= b;i++)
    {
       if(i%n==0)
       {
           blb = 1;
           break;
       }
    }
    if(blb==1)
        cout<<"OK\n";
    else
        cout<<"NG\n";
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<set>
#include<string>
using namespace std;

int n,q,s[100000],c;
set<int> se,se2;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		se2.insert(a);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		int a;
		cin>>a;
		se.insert(a);
	} 
	for(set<int>::iterator itr=se2.begin();itr!=se2.end();itr++){
		if(se.count(*itr)==1){
			c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 10096
#include <iostream>
using namespace std;
 
int main(){
    int m, f, r;
    while(true){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r == -1) break;
        if(m==-1 || f==-1){
            cout << 'F';
        }else if(m+f >= 80){
            cout << 'A';
        }else if(m+f >= 65){
            cout << 'B';
        }else if(m+f >= 50){
            cout << 'C';
        }else if(m+f >= 30){
            if(r >= 50){
                cout << 'C';
            }else{
                cout << 'D';
            }
        }else{
            cout << 'F';
        }
    cout << endl;
    }
}


Measured memory_bytes: 3092
#include <stdio.h>
int p=0;
int solve(int n){
    int i=1,k=0,l=1;
    while(i<n){
        k=i;
        l=k+1;
        while(k<=n){
            
            k=k+l;
            l++;
            if(k==n){
                p++;
                break;
            }
        }
        i++;
    }
    return k;
}


int main(void){
    int n;
    while(1){
        scanf("%d",&n);
        if(n==0)
            break;
        solve(n);
       
        printf("%d\n",p);
        p=0;
    }
    
    return 0;
}

Measured memory_bytes: 1028
day = list(map(int, raw_input().split("/")))

if day[0] > 2019: print 'TBD'
elif day[0] < 2019: print 'Heisei'
elif day[1] > 4: print 'TBD'
elif day[1] < 4: print 'Heisei'
elif day[2] <= 30: print 'Heisei'
else: print 'TBD'




Measured memory_bytes: 2568
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = list(map(int, input().split()))
ans = float('inf')

for i in range(102):
    if i in P:
        continue
    if abs(ans - X) > abs(i - X):
        ans = i

print(ans)

Measured memory_bytes: 61696
#include <bits/stdc++.h>
using namespace std; 
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1));
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++){
            if (s[i-1]==t[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    string res;
    int i = n, j = m;
    while (i!=0 && j!=0){
        if (dp[i-1][j]==dp[i][j])
            i--;
        else if (dp[i][j-1]==dp[i][j])
            j--;
        else i--, j--, res.push_back(s[i]);
    }
    reverse(res.begin(), res.end());
    cout << res << "\n";
}

Measured memory_bytes: 38492
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

//typedef int kz;
//typedef long kz;
typedef long long kz;

kz gcd(kz a,kz b) { if(b==0) return a; else gcd(b,a%b); }
kz lcm(kz a,kz b) { return a*b/gcd(a,b); }

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 **/


int main(){
    int mod=1000000007;
    int n,w;
    scanf("%d",&w);
    scanf("%d",&n);
    int x[w];
    int r[n][2];
    int ans[w];

    for (int i=0;i<n;i++) {
        scanf("%d,%d",&r[i][0],&r[i][1]);
    }
    for (int i=1;i<=w;i++) {
        int tmp=i;
        for (int j=0;j<n;j++) {
            if (tmp==r[j][0]) tmp=r[j][1];
            else if (tmp==r[j][1]) tmp=r[j][0];
        }
        ans[tmp-1]=i;
    }
    for (int i=0;i<w;i++) {
        printf("%d\n",ans[i]);
    }
    return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include<cstdio>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
// #define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  string res;
  rep(i, s.length()) {
    if ((i+1)%2 != 0) {
      res += s[i];
    }
  }
  cout << res;
}


Measured memory_bytes: 592
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
  long result;
  cin >> result;
  long money = 100;
  int year = 0;
  while(money < result){
    money += money / 100;
    year++;
  }
  cout << year << endl;
  return 0;
}

Measured memory_bytes: 3628
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
signed main(){
	int n,m,co=0;
	while(cin>>n>>m,n){
		if(co++)cout<<endl;
		vvi cost(n,vi(n,inf));
		rep(i,n)cost[i][i]=0;
		vvp G(n);
		rep(i,m){
			int a,b,c;cin>>a>>b>>c;
			a--;b--;
			cost[a][b]=cost[b][a]=c;
			G[a].pb({b,c});
			G[b].pb({a,c});
		}
		rep(i,n)sort(all(G[i]));
		rep(k,n)rep(i,n)rep(j,n)
			cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);

		vvi go(n,vi(n,inf));
		rep(i,n)rep(j,n)if(i!=j)rep(k,G[i].size())if(cost[i][j]==G[i][k].second+cost[G[i][k].first][j]){
			go[i][j]=G[i][k].first;break;
		}

		int q;
		cin>>q;
		vi s(q),t(q),hu(n),ob(q);
		vs name(q);
		rep(i,q)cin>>s[i]>>t[i]>>ob[i]>>name[i];
		rep(i,q)s[i]--,t[i]--;
		while(1){
			int mi=inf,from=-1;
			rep(i,q)if(s[i]!=t[i]){
				int tim=max(ob[i],hu[s[i]]);
				if(mi>tim)mi=tim,from=s[i];
			}
			if(from==-1)break;

			int mi_t=inf,to=-1;
			rep(i,q)if(s[i]!=t[i]&s[i]==from){
				if(mi_t>ob[i])mi_t=ob[i],to=go[s[i]][t[i]];
				else if(mi_t==ob[i])to=min(to,go[s[i]][t[i]]);
			}

			hu[from]=mi+2*cost[from][to];
			rep(i,q)if(ob[i]<=mi&&s[i]==from&&go[s[i]][t[i]]==to){
				ob[i]=mi+cost[from][to];
				s[i]=to;
			}
		}
		vector<pair<int,string> >out(q);
		rep(i,q)out[i]={ob[i],name[i]};
		sort(all(out));
		rep(i,q)cout<<out[i].second<<" "<<out[i].first<<endl;
	}
}











Measured memory_bytes: 3264
S = input()

if S == "SUN":
  print(7)
elif S == "MON":
  print(6)
elif S == "TUE":
  print(5)
elif S == "WED":
  print(4)
elif S == "THU":
  print(3)
elif S == "FRI":
  print(2)
else:
  print(1)
  

Measured memory_bytes: 2940