akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
	input = input.split("\n");
	tmp = input[1].split(" ");
	
	
	var n = parseInt(input[0], 10);
	var a = [];
	
	for (var i = 0; i < n; i++) {
	a.push(parseInt(tmp[i], 10));
	}
	
	b = []
	for (var i = 0; i < a.length; i++) {
	b.push(a[i]);
	b.push(a[i]);
	}	
	
	b.sort(
	function(a,b){
    	return (a < b ? 1 : -1);
	}
	);
	
	var result = b[0];
	for (var i = 2; i < n; i++) {
	result = result + b[i];
    }
  	console.log(result);
	}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 67760
/*	
TELL YOUR CODE TO START BELIEVING IN GOD!!
THEY HATE US BECAUSE THEY AIN'T US
	ARIJIT SUR 
	duke_knight
	IIT ISM 
 WORK SO HARD THAT YOUR IDOL BECOMES YOUR COMPETITOR 
 */
#include<bits/stdc++.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define f q.front()
#define SIZE (ll)(1e5)
#define mod (ll)(1e9+7)
using namespace std;
typedef long long int ll;

int main()
{
    IOS
    int n,x,y,distance,j,i;
    cin>>n>>x>>y;
    vector<int> ans(n,0);
    for(i=1;i<n;i++)
    {
    	for(j=i+1;j<=n;j++)
    	{
    		distance = min(abs(i-j),min(abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1));
    		ans[distance]+=1;
       	}
    }
    for(i=1;i<n;i++) cout<<ans[i]<<endl;

}

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

typedef long long ll;

int main()
{
  int n;
  string s;
  char c[40][40];
  ll num[40][40];

  while(1){
    cin>>n;
    if(n==0)break;

    for(int i=0;i<40;i++){
      for(int j=0;j<40;j++){
	c[i][j]='.';
	num[i][j]=-1;
      }
    }
    for(int i=0;i<n;i++){
      cin>>s;
      for(int j=0;j<s.length();j++){
	c[i][j]=s[j];
	if('0'<=s[j] && s[j]<='9')num[i][j]=s[j]-'0';
      }
    }
      vector<int> v;
    for(int j=39;j>=1;j--){
      for(int i=n-1;i>=1;i--){
	if(num[i][j]!=-1)v.push_back(num[i][j]);
	if(c[i-1][j-1]=='+'){
	  ll sum=0;
	  for(int k=0;k<v.size();k++)sum+=v[k];
	  num[i-1][j-1]=sum;
	  v.clear();
	}
	if(c[i-1][j-1]=='*'){
	  ll sum=1;
	  for(int k=0;k<v.size();k++)sum*=v[k];
	  num[i-1][j-1]=sum;
	  v.clear();
	}
      }
    }
    cout<<num[0][0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,a,b) for(int i=(a);i<=(b);i++)
#define P pair<int,int>
using namespace std;

int dx[8]={-1,-1,0,1,1,1,0,-1};
int dy[8]={0,-1,-1,-1,0,1,1,1};

int h,w;
int a[1002][1002];
string s[1002];

int make(int x,int y)
{
	int ans=0;
	rep(i,8)
	{
		int tx=x+dx[i];
		int ty=y+dy[i];
		if(s[tx][ty]=='.')ans++;
	}
	return ans;
}

int main()
{
	cin>>h>>w;
	rep(i,h)cin>>s[i];
	vector<P> f[2];
	int now=0,pre=1,ans=0;
	bool flag;
	rrep(i,1,h-2)
	{
		rrep(j,1,w-2)
		{
			rep(k,8)if(s[i+dx[k]][j+dy[k]]=='.')a[i][j]++;
			if(s[i][j]!='.'&&s[i][j]-'0'<=a[i][j])f[now].pb(mp(i,j));
		}
	}
	while(1)
	{
		flag=false;
		now=!now;
		pre=!pre;
		f[now].clear();
		rep(i,f[pre].size())
		{
			P p=f[pre][i];
			if(s[p.fi][p.se]!='.'&&s[p.fi][p.se]-'0'<=a[p.fi][p.se])
			{
				flag=true;
				s[p.fi][p.se]='.';
				rep(j,8)
				{
					int tx=p.fi+dx[j];
					int ty=p.se+dy[j];
					if(tx<=0||tx>=h-1||ty<=0||ty>=w-1)continue;
					a[tx][ty]++;
					if(s[tx][ty]!='.'&&s[tx][ty]-'0'==a[tx][ty])f[now].pb(mp(tx,ty));
				}
			}
		}
		if(flag)ans++;
		else break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7956
h,w=map(int,input().split())
s=[input() for _ in range(h)]
hdp=[[0]*w for _ in range(h)] # hdp[i][j]:i,jマスに明かりを置いた時のてらせる縦マス数
wdp=[[0]*w for _ in range(h)] # wdp[i][j]:i,jマスに明かりを置いた時のてらせる横マス数
for i in range(h):
  for j in range(w):
    if s[i][j]=='#':
      continue
    if j>0 and wdp[i][j-1]>0:
      wdp[i][j]=wdp[i][j-1]
    else:
      for k in range(j,w):
        if s[i][k]=='#':
          break
        wdp[i][j]+=1
    if i>0 and hdp[i-1][j]>0:
      hdp[i][j]=hdp[i-1][j]
    else:
      for k in range(i,h):
        if s[k][j]=='#':
          break
        hdp[i][j]+=1
ans=0
for i in range(h):
  for j in range(w):
    ans=max(ans,hdp[i][j]+wdp[i][j]-1)
print(ans)


Measured memory_bytes: 123992
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> A;
  Out(A+A*A+A*A*A);
  
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

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

int main(){
    int N,MAX=0;
    string S;
    cin>>N>>S;
    rep(i,N-1){
        int d[30],count=0;
        memset(d,0,sizeof(d));
        rep(j,i+1){
            int a=int(S[j]);
            d[a-97]=1;
        }
        for(int j=i+1;j<N;j++){
            int b=int(S[j]);
            if(d[b-97]==1){
                count++;
                d[b-97]=-1;
            }
        }
        MAX=max(MAX,count);
    }
    cout<<MAX<<endl;
    return 0;
}

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

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

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1 << 30; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline void maxch(int& a, int b) { if (a < b) a = b; }

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

	cout << (int) ((x / 100) * 5 >= (x % 100)) << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int a,temp=0,x,i;
	for(i=0;i<5;i++){
		scanf("%d",&a);
		if(a>=40){
			temp+=a;
		}
		else{
			temp+=40;
		}
	}
	x=temp/5;
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 1028
n,m = map(int,input().split())
if n == 0:
  print(int(m*(m-1)/2))
elif n == 1:
  if m == 1:
    print('0')
  else:
    print(int(m*(m-1)/2))
elif m == 0:
  print(int(n*(n-1)/2))
elif m == 1 and n>=2:
  print(int(n*(n-1)/2))
else:
  print(int(m*(m-1)/2 + n*(n-1)/2))

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

int main()
{
     int count;
     cin >> count;
     while(count--) {
          int num[10];
          for (int i = 0; i < 10; i++) cin >> num[i];
          int max = num[0];
          num[0] = 0;
          for (int i = 1; i < 10; i++) {
               if (num[i] > max) {
                    max = num[i];
                    num[i] = 0;
               }
          }
          max = 0;
          int flag = 1;
          for (int i = 0; i < 10; i++) {
               if (max <= num[i]) max = num[i];
               else if (num[i] != 0) {
                    cout << "NO" << endl;
                    flag = 0;
                    break;
               }
          }
          if (flag) cout << "YES" << endl;
     }

     return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
#include <complex>
using namespace std;
typedef complex<double> P;
double cp(P a, P b){
	return (conj(a)*b).imag();
}
int main(){
	P p[4];
	double x,y;
	while(cin >> x){
		cin >> y;
		p[0] = P(x,y);
		for(int i = 1; i < 4; ++i){
			cin >> x >> y;
			p[i] = P(x,y);
		}
		for(int i = 0 ;i < 3; ++i) p[i] -= p[3];
		if(cp(p[0],p[1])*cp(p[1],p[2]) > 0 && cp(p[0],p[1])*cp(p[2],p[0]) > 0) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 1220
n=input()
s=list(map(int,input().split(" ")))
i=0
x=0
while i!=len(s):
    x=x+s[i]
    i=i+1
i=0
y=0
z=0
while y<x/2:
    y=y+s[i]
    i=i+1
a=[]
a.append(y-(x-y))
z=y-s[i-1]
a.append((x-z)-z)
print(min(a))



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

using namespace std;

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

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

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

	int ans = 0;
	for(int i = 0; i < k; ++i) {
		ans += p[i];
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())]
int n,m,q;
vector<int>edge[200005];
int x[200005],y[200005],z[200005],col[200005];
bool used[200005][12];
int main(){
	cin>>n>>m;
	rep(i,m){
		int a,b;scanf("%d%d",&a,&b);
		edge[a].pb(b);
		edge[b].pb(a);
	}
	cin>>q;
	rep(i,q){
		scanf("%d%d%d",&x[q-1-i],&y[q-1-i],&z[q-1-i]);
	}
	rep(i,q){
		if(used[x[i]][y[i]]) continue;
		queue<P>que;
		que.push(mp(x[i],y[i]));
		while(!que.empty()){
			P p = que.front(); que.pop();
			if(used[p.fi][p.sc]) continue;
			if(!col[p.fi])col[p.fi] = z[i]; used[p.fi][p.sc] = 1;
			if(p.sc == 0) continue;
			rep(j,edge[p.fi].size()){
				if(used[edge[p.fi][j]][p.sc-1]) continue;
				que.push(mp(edge[p.fi][j],p.sc-1));
			}
		}
	}
	repn(i,n) printf("%d\n",col[i]);
}

Measured memory_bytes: 14712
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(n):
  if i == 0 or i == n-1:
    continue
  elif p[i-1] < p[i] and p[i+1] > p[i]:
    ans += 1
  elif p[i-1] > p[i] and p[i+1] < p[i]:
    ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val alphabets = arrayOf("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")

    val C = sc.next()

    val al = alphabets.size - 1
    for (i in 0..al) {
        if (C == "z") {
            println("a")
            break
        } else if (C == alphabets[i]) {
            println(alphabets[i + 1])
        }
    }
}

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

int solve() {
    string X;
    cin >> X;
    int s = 0, t = 0;
    for ( int i = 0; i < X.size(); i++ ) {
        if ( X[i] == 'S' ) {
            s++;
        } else {
            if ( s > 0 ) s--;
            else t++;
        }
    }
    int ans = t + s;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>

using std::vector;
using std::map;
using std::string;
using std::pair;
using std::cin;
using std::cout;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int h, w, n;
    cin >> h >> w >> n;
    int a[h][w];
    int c = 0;
    int k = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (c == 0) {
                cin >> c;
                k++;
            }
            if (i % 2 == 0) {
                a[i][j] = k;
            } else {
                a[i][w - 1 - j] = k;
            }
            c--;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << a[i][j] << " ";
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=100010,INF=1<<30;
int N,a[maxn],mn[maxn],mx[maxn],idmn[maxn],idmx[maxn];
bool vis[maxn];
int main(){
	//freopen("in","r",stdin);
	N=read();read();
	for(int i=1;i<=N;i++)
		a[i]=read();
	mn[0]=INF,mx[N+1]=-INF;
	for(int i=1;i<=N;i++){
		mn[i]=mn[i-1],idmn[i]=idmn[i-1];
		if(a[i]<mn[i])
			mn[i]=a[i],idmn[i]=i;
	}
	for(int i=N;i>=1;i--){
		mx[i]=mx[i+1],idmx[i]=idmn[i+1];
		if(a[i]>mx[i])
			mx[i]=a[i],idmx[i]=i;
	}
	int diff=0;
	for(int i=1;i<N;i++)
		diff=max(diff,mx[i+1]-mn[i]);
	for(int i=1;i<N;i++)
		if(diff==mx[i+1]-mn[i])
			vis[idmx[i+1]]=vis[idmn[i]]=1;
	int ans=0;
	for(int i=1;i<=N;i++)
		ans+=vis[i];
	printf("%d\n",ans/2);
	return 0;
}



Measured memory_bytes: 2304
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>
# include <map>


using namespace std;


int n;


bool make(string s, string s_) {
    int pos = 0;
    for (int i=0; i<n; i++) {
        if (s[i] == s_[pos]) pos++;
    }

    return pos == 3;
}


int main() {
    cin >> n;
    string s; cin >> s;
    string s_;

    int ans = 0;
    for (int i=0; i<1000; i++) {
        if (i<10) s_ = "00" + to_string(char(i));
        else if (i<100) s_ = "0" + to_string(char(i));
        else s_ = to_string(i);
        if (make(s, s_)) ans++;
    }

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



Measured memory_bytes: 384
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;


int main(int argc, const char * argv[]) {
    
    string s, ans = "No";
    cin >> s;
    
    for(int i=0; i<s.length(); i=i+2)
    {
        
        if(s[i] == 'h' && s[i+1] == 'i')
        {
            ans = "Yes";
        } else {
            ans = "No";
            break;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    cout << fixed << setprecision(8);
    double a, b, c, deg;
    cin >> a >> b >> c;
    deg = c * M_PI / 180;

    double s, l, h;
    s = a * b * sin(deg) / 2;
    l = sqrt(a * a + b * b - 2 * a * b * cos(deg)) + a + b;
    h = b * sin(deg);

    cout << s << endl;
    cout << l << endl;
    cout << h << endl;

    return 0;
}



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

using namespace std;

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

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


Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;

  ll mo = pow(3,n-1) * 2;
  ll buf = 1;
  ll ans = 0;

  rep(i,n)
  {
    ll a;
    cin >> a;
    while(1)
    {
      if(a % 2)
        break;
      if(a == 0)
        break;
      a = a / 2;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 1100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

ll d[400][400],A[400][400];
int N;


//(V^3)
void warshall_floyd(){
  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    }
  }
}


int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>d[i][j];
            A[i][j]=d[i][j];
        }
    }
    warshall_floyd();
    ll sum=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            sum+=A[i][j];
            if(d[i][j]<A[i][j]){
                cout<<-1<<endl;
                return 0;
            }
            for(int k=0;k<N;k++){
                if(k==i || k==j) continue;
                if(d[i][k]+d[k][j]==A[i][j]){
                    //cout<<i<<" "<<j<<endl;
                    sum-=A[i][j];
                    break;
                }
            }
        }
    }
    cout<<sum<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<ll> A(n);
    REP(i, n) cin >> A[i];
    ll ans = 0;
    REP(i, n) {
        // 奇数枚なら隣とペアを組む
        if (A[i] % 2 == 1 && A[i+1] > 0) {
            A[i] -= 1; // なくてもよい
            A[i+1] -= 1;
            ans += 1;
        }
        // 残りをできるだけペアにする
        // 整数/整数 は切り捨て
        ans += A[i]/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace::std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    vector<bitset<101>>dp(k+1);
    rep(i,k+1){
        int mex=0;
        while(dp[i][mex])mex++;
        for(int d:a){
            if(i+d<=k)dp[i+d][mex]=1;
        }
        if(i==k){
            if(mex)cout<<"First"<<endl;
            else cout<<"Second"<<endl;
        }
    }
}


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


int main()
{
    ll i,j,k,l,m,n;
    cin>>n;
    string s[n+10];

    map<string,ll>mp;
    map<string,ll>::iterator it;

    for(i=0; i<n; i++)
    {
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
        mp[s[i]]++;
    }
    bool ok = true;
    ll cnt = 0;
   for(it=mp.begin();it!=mp.end();it++)
   {
       m = it->second;
       cnt += ((m-1)*m)/2;
   }
    cout<<cnt<<endl;

}


Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
LL a[100010];
LL s[100010];
int main(){
  LL n;cin>>n;
  for(LL i=0;i<=n;i++)cin>>a[i];
  LL sum=0;
  for(LL i=n;i>=0;i--){
    sum+=a[i];
    s[i]=sum;
  }
  LL ans=0;
  LL nokori=1;
  for(LL i=0;i<=n;i++){
    //cout<<nokori<<" "<<s[i]<<endl;
    if(nokori<a[i]){
      cout<<-1<<endl;
      return 0;
    }
    ans+=min(nokori,s[i]);
    nokori-=a[i];
    nokori=min(2*nokori,s[i]);
   // cout<<ans<<endl;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5156
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 999;// 1e25;
static const ll MAX_N = 100001;

ll a[100001];
ll b[100001];
ll c[100001];
int main() {
	ll n; cin >> n;
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n)cin >> b[i];
	rep(i, 0, n)c[i] = a[i] - b[i];

	ll ans = 0;
	ll sum_nega = 0;
	ll sum = 0;
	rep(i, 0, n) {
		if (c[i] < 0) {
			sum_nega += c[i];
			ans++;
		}
		sum += c[i];
	}
	if (sum_nega >= 0) {
		cout << 0 << endl;
		return 0;
	}
	if (sum < 0) {
		cout << -1 << endl;
		return 0;
	}

	sort(c, c + n);
	reverse(c, c + n);

	rep(i, 0, n) {
		sum_nega += c[i];
		ans++;
		if (sum_nega >= 0) {
			cout << ans << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <set>
#include <cmath>
#include <math.h>
#include <sstream> 
 
using namespace std;
 
long long int d(int a){
    if(a==1){
        return 1;
    }else if(a==0){
        return 2;
    }else{
        return (d(a-1)+d(a-2));
    }
}
 
int main(){
    int n;
    cin>>n;
    long long int a,b,ans=0;
    a=2;
    b=1;
    if(n==0){
        cout<<2<<endl;
    }else if(n==1){
        cout<<1<<endl;
    }else{
        for(int i=0;i<n-1;i++){
            ans=(b+a);
            a=b;
            b=ans;
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main() {
  int W , A, B;
  cin >> W >> A >> B;

  if (A + W < B) {
    cout << B - (A + W) << endl;
  } else if (B + W < A) {
    cout << A - (B + W) << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
 
#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))
 
Int cnt, res;
string str;
int main(){
  cin >> str;
  for(char c:str){
    if(c == 'T')cnt++;
    else cnt--;
    res = max(res, cnt);
  }
  cout << res*2 << endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    
    vector<int> h(n);
    cin >> h.at(0);
    
    int ans = 0;
  int step = 0;
    for(int i=1; i<n; i++){
        cin >> h[i];
        if(h.at(i)<=h.at(i-1))step++;
        else step = 0;
      ans = max(ans, step);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int n;
ll mn_x = 0x3f3f3f3f3f3f3f3f, mx_x = 0xc0c0c0c0c0c0c0c0, mn_y = 0x3f3f3f3f3f3f3f3f, mx_y = 0xc0c0c0c0c0c0c0c0;

int main(){
	cin >> n;
	rep(i, n){
		ll x, y;
		cin >> x >> y;
		mn_x = min(mn_x, x + y);
		mx_x = max(mx_x, x + y);
		mn_y = min(mn_y, x - y);
		mx_y = max(mx_y, x - y);
	}
	cout << max(mx_x - mn_x, mx_y - mn_y) << endl;
	return 0;
}

Measured memory_bytes: 3620
def partition(A, p, r):
    x = A[r]
    i = p - 1

    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i+1], A[r] = A[r], A[i+1]
    return i+1


n = int(input())
A = list(map(int, input().split()))

p = partition(A, 0, n-1)
first = ' '.join(str(a) for a in A[0:p])
second = ' '.join(str(a) for a in A[p+1:n])
print(first + " [" + str(A[p]) + "] " + second)


Measured memory_bytes: 16392
# C - 4-adjacent

n = int(input())
a = list(map(int, input().split()))

b = [ a[i]%4 for i in range(n) ]
import collections
c = collections.Counter(b)
#print(c)
if ( c[2]%2 + c[1] + c[3] > 1 + c[0] ):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 14252
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const input = inputList[0].split(" ")
    const A = parseInt(input[0]);
    const B = parseInt(input[1]);
    const H = parseInt(input[2]);
    const M = parseInt(input[3]);

    // 時針の角度(360度/720分)
    const angleA = 0.5 * ((H * 60) + M);
    // 分針の角度(360度/60分)
    const angleB = 6 * M

    // 時針の角度=分針の角度の時は際は指針の差異と一致する
    if (angleA == angleB) {
        console.log(Math.abs(A - B));
    } else {
        const difAngle = Math.abs(angleA - angleB);
        const radDifAngle = (difAngle/360)* 2 * Math.PI;
        // 余弦定理
        console.log(Math.sqrt((A * A) + (B * B) - (2 * A * B * Math.cos(radDifAngle))));
    }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29904
n = int(input())
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]

max_score = 0
for i in range(n):
    score = sum(a1[:i+1]) + sum(a2[i:])
    max_score = max(score, max_score)

print(max_score)

Measured memory_bytes: 3060
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int d[300000];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		d[z] = 1;
	}
	int n = 0;
	for (int i = 0; i < 300000; i++)n += d[i];
	if (n % 2 == 0)n--;
	printf("%d\n", n);
}

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


int main() {
    ios_base::sync_with_stdio(false);

    int n,q;
    cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s[i];
    cin >> q;
    vector<int> t(q);
    rep(i,q) cin >> t[i];
    sort(s.begin(),s.end());
    int ans=0;
    rep(i,q) {
        int j=upper_bound(s.begin(),s.end(),t[i])-lower_bound(s.begin(),s.end(),t[i]);
        if (j>0) ++ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

typedef unsigned long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll pot=1;
	ll sol=0;
	if(n%2==0){
		while(pot<=n){
			pot*=5;
		}
		pot/=5;
		while(pot>1){
			sol+=n/(pot*2);
			pot/=5;
		}
		cout << sol << '\n';
	}
	else{
		cout << 0 << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"strings"
	"sort"
)

var scanner= bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		mp := make([]string, n)
		for i := range mp {
			scanner.Scan()
			mp[i] = "0" + scanner.Text() + "0"
		}
		tmp := make([]string, n+2)
		for i := range tmp {
			tmp[i] = "0"
		}
		mp = append([]string{strings.Join(tmp, "")}, mp...)
		mp = append(mp, strings.Join(tmp, ""))
		score := make([][][]int, n+2)
		for i := range score {
			score[i] = make([][]int, n+2)
			for j := range score[i] {
				score[i][j] = make([]int, 4)
			}
		}
		max_score := 0
		for i := 1; i < n+1; i++ {
			for j := 1; j < n+1; j++ {
				tmps := mp[i]
				if string(tmps[j]) == "1" {
					score[i][j][0] = score[i - 1][j][0] + 1
					score[i][j][1] = score[i][j - 1][1] + 1
					score[i][j][2] = score[i - 1][j - 1][2] + 1
					score[i][j][3] = score[i - 1][j + 1][3] + 1
					max_score = max(max_score, score[i][j][0], score[i][j][1], score[i][j][2], score[i][j][3])
				}
			}
		}
		fmt.Println(max_score)
	}
}

func max(a, b, c, d, e int) int {
	buf := []int{a, b, c, d, e}
	sort.Ints(buf)
	return buf[len(buf)-1]
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000
#define MOD 1000000007

int main(){
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	int a[n] = {};
	rep(i, n) {
		int tmp;
		cin >> tmp;
		a[tmp]++;
	}

	bool ok = true;
	rep(i, n) {
		if (n % 2 == 0) {
			if (i == 0) continue;
			if (a[i] != 2){
				ok = false;
				break;
			}
		} else {
			if (i == 0) {
				if (a[i] != 1) {
					ok = false;
					break;
				}
			} else {
				if (a[i] != 2) {
					ok = false;
					break;
				}
			}
		}
		i++;
	}

	if (ok) {
		ll tmp = 1;
		rep(i, n/2) {
			tmp = tmp * 2 % MOD;
		}
		cout << tmp << endl;
	} else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);//, SA(N+1), SB(N+1);
    rep(i,N){
        cin >> A[i];
    }
    /*
    rep(i,N){
        SA[i+1] = SA[i] + A[i];
    }*/
    rep(i,M){
        cin >> B[i];
    }
    /*
    rep(i,M){
        SB[i+1] = SB[i] + B[i];
    }*/
    ll sum = 0;
    ll ind1 = 0;
    while(ind1 < N && sum + A[ind1] <= K){
        sum += A[ind1];
        ind1++;
    }
    ll ind2 = 0;
    while(ind2 < M && sum + B[ind2] <= K) {
        sum += B[ind2];
        ind2++;
    }
    ll ans = ind1 + ind2;
    for(ll i = ind1-1;i>=0;i--){
        sum -= A[i];
        while(ind2 < M && sum + B[ind2] <= K){
            sum += B[ind2];
            ind2++;
        }
        ind1--;
        //cout << ans << " " << sum << endl;
        cmax(ans, ll(ind1+ind2));
    }
    cout << ans << endl;
}


Measured memory_bytes: 6332
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.*
import kotlin.math.*

fun main() {
    var fs = Atcoder.FastReader()
    var n = fs.next()
    if(n == n.toUpperCase()) println("A")
    else println("a")
}
private fun gcd(i: Int, j: Int):Int {
    var max = max(i, j)
    var min = min(i, j)
    var rest:Int = max%min
    var oldRest:Int = min
    while (rest != 0) {
        max = min
        min = rest
        oldRest = rest
        rest = max%min
    }
    return oldRest
}
class Atcoder {
    internal class FastReader {
        private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))
        private var st: StringTokenizer? = null

        operator fun next(): String {
            while (st == null || !st!!.hasMoreElements()) {
                try {
                    st = StringTokenizer(br.readLine())
                } catch (e: IOException) {
                    e.printStackTrace()
                }

            }
            return st!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return java.lang.Long.parseLong(next())
        }

        fun nextDouble(): Double {
            return java.lang.Double.parseDouble(next())
        }

        fun nextLine(): String {
            var str = ""
            try {
                str = br.readLine()
            } catch (e: IOException) {
                e.printStackTrace()
            }
            return str
        }

        fun readIntArray(n: Int): IntArray {
            val a = IntArray(n)
            for (i in 0 until n) a[i] = nextInt()
            return a
        }

        fun readLongArray(n: Int): LongArray {
            val a = LongArray(n)
            for (i in 0 until n) a[i] = nextLong()
            return a
        }

        fun readDoubleArray(n: Int): DoubleArray {
            val a = DoubleArray(n)
            for (i in 0 until n) a[i] = nextDouble()
            return a
        }
    }
}


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

typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
const ll INF = 1e18;
const ll mod = 1e9+7;

int main() {
    string s;
    int q;
    cin>>s>>q;
    deque<char>d;
    int n=s.size();
    rep(i,n)d.push_back(s[i]);
    int cnt=0;
    rep(i,q){
      int t1;
      cin>>t1;
      if (t1==1){
        cnt=1-cnt;
      }
      if (t1==2){
        int f;char c;
        cin>>f>>c;
        if (f==1){
          if (cnt==0){
            d.push_front(c);
          }
          if (cnt==1){
            d.push_back(c);
          }
        }
        if (f==2){
          if (cnt==1){
            d.push_front(c);
          }
          if (cnt==0){
            d.push_back(c);
          }
        }
      }

    }
    if (cnt==1)reverse(d.begin(),d.end());
    for_each(d.begin(),d.end(),[](char x){
      cout<<x;
    });



}


Measured memory_bytes: 896
import math

a,b,x=map(int,input().split())
vol=a*a*b/2
t=0

if x == vol:
    t = b/a

elif x < vol:
    t = a*b*b/2/x

else:
    t = 2*b/a - 2*x/a/a/a

ans=math.degrees(math.atan(t))
print(ans)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

const long long d = 1e9+7;
int main(){
  int N; cin >> N;     // unsigned int 2byte:0 ~ 65535
  long long  power = 1;//long :符合つき4byte
                       //long long :符合なし4byte0~4.3e+10
  for(int i=1; i<=N; i++){
    power = (power*i) % d;
  }
//A mod B AをBで割った余り
  cout << power  << endl;
}


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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    bool one = false;
    int ans = 0;
    for(int i=0; i<N; i++){
        if(one && S[i] == S[i-1]){
            if(i == N-1) break;
            i++;
            one = false;
        }else{
            one = true;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main{
	static int T, S, E, W, N, U;
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int[] in = new int[6];
		for(int i = 0; i < 6; i++){
			in[i] = scan.nextInt();
		}
		T = in[0];
		S = in[1];
		E = in[2];
		W = in[3];
		N = in[4];
		U = in[5];

		int q = scan.nextInt();
		for(int i = 0; i < q; i++){
			int n = scan.nextInt();
			int m = scan.nextInt();
			boolean flg = false;
			while(true){
				if(m == N){
					MoveSouth();
					MoveSouth();
				} else if(m == U){
					MoveSouth();
					MoveSouth();
					MoveSouth();
				} else if(m == T){
					MoveSouth();
				} else if(m == E){
					MoveEast();
					MoveEast();
					MoveEast();
				} else if(m == W){
					MoveEast();
				}
				if(m == S){
					if(n == T){
						flg = true;
						break;
					} else {
						MoveEast();
					}
				}
				
			}
			System.out.println(E);
		}

	}

	public static void MoveSouth(){
		int a = T;
		T = N;
		N = U;
		U = S;
		S = a;
	}
	public static void MoveEast(){
		int a = T;
		T = W;
		W = U;
		U = E;
		E = a;
	}
	public static void MoveNorth(){
		int a = T;
		T = S;
		S = U;
		U = N;
		N = a;
	}
	public static void MoveWest(){
		int a = T;
		T = E;
		E = U;
		U = W;
		W = a;
	}
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }
    vi x(m);
    rep(i, m) cin >> x[i];
    VSORT(x);
    vi d(m-1);
    rep(i, m-1) d[i] = x[i+1] - x[i];
    VSORT(d);
    ll ans = 0;
    rep(i, m-n) ans += d[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4032
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    S = input_raw[0]
    if A >= 3200:
        print S
    else:
        print "red"


if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
using System;
using System.Linq;

namespace Ex160506_1{
    public class Program{
        public static void Main(string[] args){
            Console.ReadLine();
            var an = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            Console.WriteLine("{0} {1} {2}", an.Min(), an.Max(), an.Sum());
        }
    }
}

Measured memory_bytes: 10224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  int i=0,j=0,k=0;
  ll ans=0;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(k=j+1;k<n;k++){
        if(a.at(i)==a.at(j) || a.at(j)==a.at(k) || a.at(i)==a.at(k)){
          continue;
        }
        if(abs(a.at(i)-a.at(j))<a.at(k) && a.at(k)<a.at(i)+a.at(j)){
          ans++;
        }
      }
    }
  }
  cout <<ans;
}

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

int main(){
  int i,a,n,k,ans=0;
  cin>>n>>k;
  vector<int> b(n+1,0);
  for(i=0;i<n;i++) cin>>a,b.at(a)++;
  sort(b.rbegin(),b.rend());
  for(i=k;i<n;i++) ans+=b.at(i);  
  cout<<ans;
}

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

int main() {
  int ans;
  vector<int> d(5);
  for (int i=0; i<5; i++){
    cin >> d.at(i);
  }
  
  for (int i=0; i<5; i++){
    if (d.at(i) == 0){
      ans = i+1;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 93193111451418101
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

bool vis[314514] = {};
ll n;
vector<ll> d;

bool DP(ll nowPos) {
  if (nowPos >= n - 1) {
    return true;
  }
  vis[nowPos] = 1;
  bool cnt = 0;
  for (int i = min(d[nowPos] / 10, n - 1 - nowPos); i >= 1; i--) {

    if (vis[nowPos + i] == false)
      cnt |= DP(nowPos + i);
    else {
      break;
    }
  }
  return cnt;
}

int main() {
  cin >> n;
  REP(i, n) {
    ll a;
    cin >> a;
    d.pb(a);
  }
  if (DP(0) == false) {
    return !printf("no\n");
  }
  REP(i, n + 1) { vis[i] = 0; }
  REP(i, n / 2) { swap(d[i], d[n - 1 - i]); }
  if (DP(0) == false) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }
}



Measured memory_bytes: 29144
#include<bits/stdc++.h>
using namespace std;
char a,b,c;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>a>>b>>c;
	if(a=='R'&&b=='R'&&c=='R')cout<<"3\n";
	else if(a=='R'&&b=='R'||b=='R'&&c=='R')cout<<"2\n";
	else if(a=='R'||b=='R'||c=='R')cout<<"1\n";
	else cout<<"0\n";
}

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

int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
    int n; cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> l(n),r(n);
    for(int i=0;i<n-1;i++) l[i+1]=gcd(l[i],a[i]);
    for(int i=n-1;i>=1;i--) r[i-1]=gcd(r[i],a[i]);
    int ans=1;
    for(int i=0;i<n;i++) ans=max(ans,gcd(l[i],r[i]));
    cout<<ans<<endl;
}

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

int main(void){
    string s;
    cin>>s;
    int n = s.size();
    rep(i,n){
        s.pop_back();
        int m = s.size();
        if(m&1) continue;
        if(s.substr(0,m/2)==s.substr(m/2,m/2)){
            cout<<m<<endl;
            return 0;
        }
    }
    return 0;
}


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

int main(int argc,char const* argv[])
{
  long long n;
  long long ans=0;
  int p;
  cin >> n;
  p=n%11;
  if(p==0) p=0;
  else if(p>6)p=2;
  else p=1;
  ans=(n/11)*2+p;
  cout << ans << endl;
     
  return 0;
}


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

using namespace std;

int main(void){
    int n;
    cin >> n;
    int i;
    long max=0;
    long ans=0;

    
    for(i=1;i<n;i++){
        max += i;
      	
    }
    
    
    cout << max << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

// 先頭がB以外が最低1つあればAとBの最小値が答え
func main() {
	var N, ans, a, b, c int
	fmt.Scan(&N)
	var s = make([]string, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&s[i])
		ans += strings.Count(s[i], "AB")
		aaa := strings.HasSuffix(s[i], "A")
		bbb := strings.HasPrefix(s[i], "B")
		if aaa {
			a++
		}
		if bbb {
			b++
		}
		if aaa && bbb {
			c++
		}
	}
	if a == 0 || b == 0 {
	} else if a == c && b == c {
		ans += a - 1
	} else if a == c {
		ans += a
	} else if b == c {
		ans += b
	} else if a > b {
		ans += b
	} else {
		ans += a
	}
	// fmt.Printf("%v %v %v\n", a, b, c)
	fmt.Printf("%v\n", ans)
}


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <iomanip>
#include <bits/stdc++.h>
#include <fstream>
#include <map>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int x,cnt=0;
    string s;
    cin >> x >> s;
    if(x>=s.size()) cout << s << endl;
    else cout << s.erase(x) + "..." << endl;
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
int lower_case(char x[],int n,bool b){
    for(int i=0;i<n;i++)
        if(x[i]>=65&&x[i]<=90)
            {b=1;break;}
return b;}

int main(){
string s,t,u;
int a,p;
bool b = 0;
cin>>s>>t;
int n = s.length(),m=t.length();
int x1,x2;
char x[n+1],y[m+1];
strcpy(x,s.c_str());strcpy(y,t.c_str());
x1=lower_case(x,n,b);
x2=lower_case(y,m,b);
if(x1==0&&x2==0&&n<=100&&m<=100&&n>=1&&m>=1){
    cout<<t+s<<endl;
}


return 0;}


Measured memory_bytes: 3560
#include <iostream>
#include <cmath>
using namespace std;
int n, x, a, g;
int f(int p, int q) {return q ? f(q, p%q) : p;}

int main() {
	cin>>n>>x;
	for(int i=0; i<n; i++) {
		scanf("%d", &a);
		a = abs(a-x);
		g = i ? f(a, g) : a;
	}
	cout<<g;
	return 0;
}

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

#define a 10000
#define b 5000
#define c 1000

void solve(){
  int n,y,num;
  int d[3]={0,0,0};
  scanf("%d %d",&n,&y);
    
    d[0]=(int)(y/a);
    y%=a;
    d[1]=(int)(y/b);
    y%=b;
    d[2]=(int)(y/c);
    y%=c;
    num=d[0]+d[1]+d[2];
    while(num<n){
      if(num+4<=n){
        if(d[1]>0){
          d[1]--;
          d[2]+=5;
        }else if(d[0]>0){
          d[0]--;
          d[1]+=2;
        }else{
          break;
        }
      }else if(d[0]>0){
          d[0]--;
          d[1]+=2;
      }else{
          break;
      }
     num=d[0]+d[1]+d[2];
    }
    if(num==n)printf("%d %d %d\n",d[0],d[1],d[2]);
    else printf("-1 -1 -1\n");
}
int main(){
  /*
  int q;
  scanf("%d",&q);
  while(--q)solve();
  */
  solve();

  return 0;
}

Measured memory_bytes: 3828