akhauriyash/Code-Regression huggingface dataset:
/*	ex7_1
	suzuto	*/

#include <stdio.h>

typedef struct point{ /*直交座標を表す構造体を作る*/
  int x_elem;
  int y_elem;
}point;

/*プロトタイプ宣言*/
void point_scanf(point *ptr);
void point_printf(point z);
point shift_point(point bef_point, int move_x, int move_y);

int main(void) {
  point point_1, point_2, point_3, point_4, vect_1to2, vect_2to3, vect_3to4; /*変数の宣言*/
  point *ptr_1 = &point_1, *ptr_2 = &point_2;

  point_scanf(ptr_1); /*既知の座標を入力*/
  point_scanf(ptr_2);

  vect_1to2.x_elem = point_2.x_elem - point_1.x_elem; /*point_1からpoint_2へのベクトル(point_1を原点としてみたときのpoint_2の座標)*/
  vect_1to2.y_elem = point_2.y_elem - point_1.y_elem;

  vect_2to3.x_elem = -1 * vect_1to2.y_elem; /*point_2からpoint_3へのベクトル = vect_1to2を時計回りに90度回転*/
  vect_2to3.y_elem = vect_1to2.x_elem;

  vect_3to4.x_elem = -1 * vect_1to2.x_elem; /*point_3からpoint_4へのベクトル = vect_1to2を時計回りに180度回転*/
  vect_3to4.y_elem = -1 * vect_1to2.y_elem;

  /*未知の座標を算出*/
  point_3 = shift_point(point_2, vect_2to3.x_elem, vect_2to3.y_elem);
  point_4 = shift_point(point_3, vect_3to4.x_elem, vect_3to4.y_elem);

  point_printf(point_3); /*結果を出力*/
  printf(" ");
  point_printf(point_4);
  printf("\n");
  return 0;
}

void point_scanf(point *ptr){ /*point型を入力をする関数を定義*/
  scanf("%d %d", &(ptr->x_elem), &(ptr->y_elem));
}

void point_printf(point z){ /*point型を出力をする関数を定義*/
  printf("%d %d", z.x_elem, z.y_elem);
}

point shift_point(point bef_point, int move_x, int move_y){ /*bef_pointをxの正の方向にmove_x、yの正の方向にmove_yだけ動かした座標aft_pointを返す*/
  point aft_point; /*変数の宣言*/
  aft_point.x_elem = bef_point.x_elem + move_x; /*x方向の移動*/
  aft_point.y_elem = bef_point.y_elem + move_y; /*y方向の移動*/
  return aft_point;
}


Measured memory_bytes: 1700
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

set<int> s;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if (s.size()==2) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3592
#include<stdio.h>
int main(void) {

	int n;
	int i;
	int a[10000];
	int c_1 = 1;
	int c_2 = 1;
	int c_3 = 1;
	int c_4 = 1;
	int c_5 = 1;
	int c_6 = 1;
	int c_7 = 1;
	int c_8 = 1;
	int sum = 0;
	int sum_ = 0;
	int min = 0;
	int max = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	for (i = 0; i < n; i++) {
		if (a[i] >= 1 && a[i] < 400 && c_1 == 1) {
			sum++;
			c_1 = 0;
		}
		else if (a[i] >= 400 && a[i] < 800 && c_2 == 1) {
			sum++;
			c_2 = 0;
		}
		else if (a[i] >= 800 && a[i] < 1200 && c_3 == 1) {
			sum++;
			c_3 = 0;
		}
		else if (a[i] >= 1200 && a[i] < 1600 && c_4 == 1) {
			sum++;
			c_4 = 0;
		}
		else if (a[i] >= 1600 && a[i] < 2000 && c_5 == 1) {
			sum++;
			c_5 = 0;
		}
		else if (a[i] >= 2000 && a[i] < 2400 && c_6 == 1) {
			sum++;
			c_6 = 0;
		}
		else if (a[i] >= 2400 && a[i] < 2800 && c_7 == 1) {
			sum++;
			c_7 = 0;
		}
		else if (a[i] >= 2800 && a[i] < 3200 && c_8 == 1) {
			sum++;
			c_8 = 0;
		}
		else if (a[i] >= 3200)sum_++;
	}

	min = sum;
	max = sum+sum_;
	if (min == 0)min = 1;

	printf("%d %d", min, max);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

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


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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; }

using ll = long long;
using P = std::pair<ll, ll>;
using PP = std::pair<ll, P>;

const ll INF = 1ll<<60;

ll N, M, S;
std::vector<P> G[60*2510];
std::priority_queue<P, std::vector<P>, std::greater<P>> pque;
ll A[110], B[110], U[110], V[110];
ll C[100], D[100];
ll dist[60*2510];
std::vector<P> edge[60];

ll pr( ll v, ll rest )
{
  return v*2500+rest;
}

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

  rep( i, M )
  {
    std::cin >> U[i] >> V[i] >> A[i] >> B[i];
    --U[i]; --V[i];

    edge[U[i]].emplace_back( V[i], i );
    edge[V[i]].emplace_back( U[i], i );
  }

  rep( i, N )
    std::cin >> C[i] >> D[i];

  rep( i, N ) rep( j, 2500 )
  {
    ll from = pr( i, j ), to = pr( i, std::min( j+C[i], 2499ll ) );

    G[from].emplace_back( to, D[i] );

    for( auto e : edge[i] )
    {
      ll u = e.first;
      ll idx = e.second;

      if( j-A[idx] >= 0 )
        G[from].emplace_back( pr( u, j-A[idx] ), B[idx] );
    }
  }

  rep( i, 50*2505+5 )
    dist[i] = INF;

  S = std::min( S, 2499ll );

  dist[pr(0,S)] = 0;
  pque.emplace( dist[pr(0,S)], pr(0,S) );

  while( !pque.empty() )
  {
    P p = pque.top(); pque.pop();
    ll d = p.first, v = p.second;

    if( d > dist[v] )
      continue;

    for( auto u : G[v] )
    {
      ll to = u.first, cost = u.second;

      if( chmin( dist[to], dist[v]+cost ) )
        pque.emplace( dist[to], to );
    }
  }

  repi( i, 1, N )
  {
    ll ans = INF;

    rep( j, 2500 )
      chmin( ans, dist[pr(i,j)] );

    std::cout << ans << std::endl;
  }

  return 0;
}

Measured memory_bytes: 23860
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    cin >> a >> b >>c;
    int count;
        count = 0;
    int N = b - a + 1;
    for (int i = 0; i < N; i++){
        if (c % a == 0){
            count++;
        }
        a++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3092
#include <stdio.h>

char s[200000];//文字列//

int main(void) {

	int i, j;
	int firsta;
	int lastz;
	int count;
	int max = 0;
	int len;

	scanf("%s", s);

	len = strlen(s);

	for (i = 0; i <= len - 1; i++) {
		if (s[i] == 'A') {
			firsta = i;
			break;
		}
	}

	for (j = len; j >= 0; j--) {
		if (s[j] == 'Z') {
			lastz = j;
			break;
		}
	}

	max = lastz - firsta + 1;

	printf("%d", max);

	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;

const int INF = 0x3f3f3f3f;
const int maxn = 1000010;

//变量
int n, m, root;
int a[maxn] = { 0 }; 
int ch[maxn][2];//记录儿子，0为左儿子，1为右儿子
int val[maxn];//当前点对应的值
int fa[maxn];//记录当前结点的父亲
int siz[maxn] = { 0 };//记录子树大小
int mx[maxn];//记录区间最值
int tag1[maxn];//区间加的标记
int tag2[maxn];//区间翻转的标记 

inline void refresh(int now) {//对于不同题而言，更新信息也不同 
	if (!now) return;
	siz[now] = siz[ch[now][0]] + siz[ch[now][1]] + 1;
	mx[now] = max(val[now], max(mx[ch[now][0]], mx[ch[now][1]]));
} 

int build(int l, int r, int f) {
	if (l > r) return 0;
	int mid = l + r >> 1;
	fa[mid] = f;
	val[mid] = a[mid];
	ch[mid][0] = build(l, mid - 1, mid);
	ch[mid][1] = build(mid + 1, r, mid);
	refresh(mid);
	return mid;
}

void pushdown(int now) {//标记下传 
	if (tag1[now]) {
		if (ch[now][0]) {
			tag1[ch[now][0]] += tag1[now];
			mx[ch[now][0]] += tag1[now];
			val[ch[now][0]] += tag1[now];
		}
		if (ch[now][1]) {
			tag1[ch[now][1]] += tag1[now];
			mx[ch[now][1]] += tag1[now];
			val[ch[now][1]] += tag1[now];
		}
		tag1[now] = 0;
	}
	if (tag2[now]) {
		if (ch[now][0]) {
			tag2[ch[now][0]] ^= 1;
			swap(ch[ch[now][0]][0], ch[ch[now][0]][1]);
		}
		if (ch[now][1]) {
			tag2[ch[now][1]] ^= 1;
			swap(ch[ch[now][1]][0], ch[ch[now][1]][1]);
		}
		tag2[now] = 0;
	}
}

int chk(int x) {//判断这个结点是父亲的左儿子还是右儿子，是左儿子返回0，是右儿子返回1 
	return ch[fa[x]][1] == x;
} 

void rotate(int now) {//旋转操作 
	int f = fa[now], gf = fa[f], k = chk(now), w = ch[now][k ^ 1];
	ch[f][k] = w; fa[w] = f;
	ch[gf][chk(f)] = now; fa[now] = gf;
	ch[now][k ^ 1] = f; fa[f] = now;
	refresh(f); refresh(now);
} 

void splay(int now, int goal = 0) {//伸展操作 
	while (fa[now] != goal) {
		int f = fa[now], gf = fa[f];
		if (gf != goal) {
			if (chk(f) == chk(now)) rotate(f);
			else rotate(now);
		}
		rotate(now);
	} 
	if (!goal) root = now;
}

int kth(int k) {//查询第k大结点 
	int now = root;//从根结点开始搜索
	while (1) {
		pushdown(now);//多一个pushdown 
		if (ch[now][0] && k <= siz[ch[now][0]]) {
			//如果有左子树且左子树大小大于等于k，说明k在左子树上
			now = ch[now][0]; 
		}
		else if (k > siz[ch[now][0]] + 1) {
			//否则如果左子树加上当前结点的大小依然小于k，说明在右子树上
			k -= siz[ch[now][0]] + 1;
			now = ch[now][1];
		}
		else {//否则说明第k大就是当前结点 
			return now;
		}
	} 
}

int split(int l, int r) {
	l = kth(l); r = kth(r + 2);
	splay(l); splay(r, l);
	return ch[r][0];
}

void updata(int l, int r, int data) {
	int now = split(l, r);
	tag1[now] += data;
	mx[now] += data;
	val[now] += data;
}

void turn(int l, int r) {
	int now = split(l, r);
	tag2[now] ^= 1;
	swap(ch[now][0], ch[now][1]);
}

int query(int l, int r) {
	return mx[split(l, r)];
}

void dfs(int now) {
	pushdown(now);
	if (ch[now][0]) dfs(ch[now][0]);
	if (val[now] != -INF) printf("%d ", val[now]);
	if (ch[now][1]) dfs(ch[now][1]);
}

int main() {
	scanf("%d", &n);
	a[1] = -INF; a[n + 2] = -INF;
	mx[0] = -INF;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i + 1]);
	}
	root = build(1, n + 2, 0);
	for (int i = 1; i <= n; ++i) {
		turn(1, i);
	}
	dfs(root);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 24960
#include <stdio.h>
#define N 2000001
#define MAX 10000
void Counting_Sort(int);
int A[N];
int B[N];
int C[N];
int n;
int main(){
    int i;
    int k=0;
    scanf("%d", &n);
    for( i=1; i<=n; i++ ){
        scanf("%d", &A[i]);
        if( A[i] > MAX ) return 0;
        else if( k < A[i] ) k=A[i];
    }
    Counting_Sort(k);
    for( i=1; i<=n; i++ ){
        printf("%d", B[i]);
        if( i+1 <= n ){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}
void Counting_Sort(int k){
    int i;
    for( i=0; i<=k; i++ ) C[i]=0;
    for( i=1; i<=n; i++ ) C[A[i]]++;
    for( i=1; i<=k; i++) C[i]+=C[i-1];
    for( i=n; i>0; i-- ){
        B[C[A[i]]]=A[i];
        C[A[i]]--;
    }
}

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

typedef signed long long ll;

int main() {
    string S, token;
    stringstream ss;
    cin >> S;
    ss << S;
    bool first = true;

    for(; getline(ss, token, ',');) {
        if(!first) cout << " ";
        cout << token;
        first = false;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	inp(n) inp(k)
	int ans=0;
	for(int i=k;i<=n+1;i++)
	{
		int tans=(n+1)*i-(i*(i-1))/2-(i*(i+1))/2+1;
		tans%=mod;
		ans+=tans;
		ans%=mod;
	}
	ans+=mod;
	ans%=mod;
	cout<<ans<<'\n';
	printclock;
}

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

int main(){
  int n,p; cin>>n>>p;
  vector<vector<long long>> C(n+1,vector<long long>(n+1));
  long long c0=0,c1=0;
  for(int i=0;i<n;i++){
    int a; cin>>a;
    if(a%2==0) c0++;
    else c1++;
  }C[0][0]=1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=i;j++){
      if(j==0 || j==i) C[i][j]=1;
      else C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
  }
  long long re=pow(2,c0),ans=0;
  for(int bit=0;bit<=c1;bit++){
    if(bit%2==p) ans+=re*C[c1][bit];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator<(const Puzzle &p)const{
    for(int i=0;i<N2;i++){
      if(f[i]==p.f[i])continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};
static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};

bool func(Puzzle p){
  for(int i=0;i<N2;i++)
    if(p.f[i]!=(i+1))return false;
  return true;
}
string func1(Puzzle s){
  queue<Puzzle>Q;
  map<Puzzle,bool>V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;
  while(!Q.empty()){
    u=Q.front();Q.pop();
    if(func(u))return u.path;
    int sx=u.space/N;
    int sy=u.space%N;
    for(int r=0;r<4;r++){
      int tx=sx+dx[r];
      int ty=sy+dy[r];
      if(tx<0||ty<0||tx>=N||ty>=N)continue;
      v=u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
	V[v]=true;
	v.path+=dir[r];
	Q.push(v);
      }
    }
  }
  return "unsolvable";
}
int main(){
  Puzzle in;
  for(int i=0;i<N2;i++){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans=func1(in);
  cout<<ans.size()<<endl;
  return 0;
}
			  



Measured memory_bytes: 30596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

int main() {
    std::string s;
    std::cin >> s;

    std::string ans = "None";
    for (int i = 'a'; i <= 'z'; i++) {
        bool f = false;
        for (int j = 0; j < s.size(); j++)
        {
            if(i == s[j]) {
                f = true;
            }
        }
        if(!f) {
            ans = i;
            break;
        }
    }

    std::cout << ans << "\n";
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define debug1(a) cout<<#a<<" "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<" "#c<<" "<<(c)<<endl;
typedef long double ld;
void solve()
{
	int n;
	cin >> n;
	if (n == 0)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}


}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int t;
	t = 1;
	while (t--)
	{
		solve();
	}
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	vi s(n);
	int all = 0;
	rep(i, n) {
		cin >> s[i];
		all += s[i];
	}
	sort(ASC(s));
	if (all % 10 == 0) {
		int ma = 0;
		rep(i, n) {
			int tmp = all - s[i];
			if (tmp % 10 == 0) tmp = 0;
			ma = max(ma, tmp);
		}
		cout << ma << endl;
	}
	else cout << all << endl;

}


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

using namespace std;
typedef long long int ll;

ll INF = 114514191919119;

int main(){

    ll a, b, c;
    cin >> a >> b >> c;

    if(b - a == c - b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    long double l;
    cin >> l;
    l/=3;
    l=l*l*l;
    printf("%.7Lf\n",l);
    return 0;
}

Measured memory_bytes: 3792
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve1():
    _ = int(input())
    L = list(map(int, input().split()))

    S = sum([abs(v) for v in L])
    if len(list(filter(lambda x: x < 0, L))) % 2 == 0:
        print(S)
    else:
        print(S-2*(min([abs(v) for v in L])))


def solve2():
    N = int(input())
    L = list(map(int, input().split()))
    dp = [[0]*(N+1) for _ in range(2)]
    dp[1][0] = -float('inf')
    for i in range(N):
        dp[0][i+1] = max(dp[0][i]+L[i], dp[1][i]-L[i])
        dp[1][i+1] = max(dp[0][i]-L[i], dp[1][i]+L[i])
    print(dp[0][-1])


solve2()


Measured memory_bytes: 60144
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

 
int main() {

    int a,b,c;
    cin >> a >> b >> c;

    int d =max(a,(max(b,c)))- (a + b + c - max(a,max(b,c)) - min(a,(min(b,c))));
    int e = max(a,(max(b,c))) - min(a,min(b,c));

    if((e-d) % 2 == 0) {
        cout<<d + (e-d)/2<<endl;
    }
    else {
        cout<< d + (e-d)/2 + 2 <<endl;
    }

 return 0;
}

Measured memory_bytes: 256
import math
def calcAngle(h,m): 
    if (h == 12): 
        h = 0
    if (m == 60): 
        m = 0
        
    # Calculate the angles moved by  
    # hour and minute hands with  
    # reference to 12:00 
    hour_angle = 0.5 * (h * 60 + m) 
    minute_angle = 6 * m 
        
    # Find the difference between two angles 
    angle = abs(hour_angle - minute_angle) 
        
    # Return the smaller angle of two  
    # possible angles 
    angle = min(360 - angle, angle) 
        
    return angle 


A,B,H,M = map(int,input().split())

angle = calcAngle(H,M)
angle_rag = math.radians(angle)
out = (A**2 + B**2 - 2 * A * B * math.cos(angle_rag))**0.5
print(out)

Measured memory_bytes: 9524
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string S;
    cin >> S;

    set<char> s;
    int ans = 0;
    FOR(i, 0, S.size() - 1) {
        s.insert(S[i]);
        int tmp = 0;
        for (auto c : s) {
            FOR(j, i + 1, S.size()) {
                if (c == S[j]) {
                    tmp++;
                    break;
                }
            }
        }
        chmax(ans, tmp);
    }

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


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

int main() {
  string S;
  cin >> S;
  string s = "", t = "";
  int ans = 0;
  for (int i = 0; i < S.size(); ++i) {
    s += S[i];
    if (s != t)
      t = s, s = "", ++ans;
  }
  cout << ans << endl;
}

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

using namespace std;

int N, Q;
vector< int > g[100000];
vector< int > query[100000];
int sz[100000];

int lca[100000];
bool buf[100000];

void sub(int idx)
{
  sz[idx] = query[idx].size();
  for(auto &to : g[idx]) {
    sub(to);
    sz[idx] += query[to].size();
  }
}

void dfs(int idx, bool keep)
{
  int heavy = -1;
  for(auto &to : g[idx]) {
    if(heavy == -1 || sz[to] > sz[heavy]) heavy = to;
  }
  for(auto &to : g[idx]) {
    if(heavy != to) dfs(to, false);
  }

  if(~heavy) {
    dfs(heavy, true);
    for(int &v: query[idx]) {
      if(~lca[v]) continue;
      if(buf[v]++) lca[v] = idx;
      else query[heavy].push_back(v);
    }
    query[idx].swap(query[heavy]);
  } else {
    for(int &v: query[idx]) {
      if(~lca[v]) continue;
      if(buf[v]++) lca[v] = idx;
    }
  }

  for(auto &to : g[idx]) {
    if(to == heavy) continue;
    for(int &v : query[to]) {
      if(~lca[v]) continue;
      if(buf[v]++) lca[v] = idx;
      else query[idx].push_back(v);
    }
  }

  if(!keep) for(auto &v : query[idx]) buf[v] = false;
}

int main()
{
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    int K;
    scanf("%d", &K);
    while(K--) {
      int U;
      scanf("%d", &U);
      g[i].push_back(U);
    }
  }
  scanf("%d", &Q);

  memset(lca, -1, sizeof(lca));

  for(int i = 0; i < Q; i++) {
    int U, V;
    scanf("%d %d", &U, &V);
    if(U == V) {
      lca[i] = V;
    } else {
      query[U].push_back(i);
      query[V].push_back(i);
    }
  }

  sub(0);
  dfs(0, false);
  for(int i = 0; i < Q; i++) {
    printf("%d\n", lca[i]);
  }
}

Measured memory_bytes: 26604
var
	n, m, k : integer;
	i : integer;
    ok : boolean;
    
begin
	ok := true;
	readln(n, m);
	for i := 1 to m do 
    begin
 		read(k);
    	n := n - k;
        if n < 0
        	then ok := false;
    end;
    if ok then
    	writeln(n)
    else
    	writeln(-1);
end.

Measured memory_bytes: 1384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        int s = 0;
        final int MOD = 1_000_000_007;
        try (Scanner sc = new Scanner(System.in)) {
            s = sc.nextInt();
        }
        int[][] pascal = new int[s][];
        pascal[0] = new int[1];
        pascal[0][0] = 1;
        for (int i = 1; i < s; i++) {
            pascal[i] = new int[i + 1];
            for (int j = 0; j < i; j++) {
                int tmp = pascal[i - 1][j] % MOD;
                pascal[i][j] += tmp;
                pascal[i][j + 1] += tmp;
            }
        }
        
        long result = 0;
        for (int p = 1; ; p++) {
            s -= 3;
            if (s < 0) break;
            result = (result + pascal[s + p - 1][p - 1]) % MOD;
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 44120
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	int k, s;
	int n, m;
	int x, y;
	bool z = true;
	int ans = 0;


	scanf("%d %d %d", &x,&y,&k);
	
	s = x*y;
	if (s < k)z = true;
	else z = false;

	if (z)printf("%d\n",s);
	else printf("%d\n",k);

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <vector>
#include <algorithm>
#define pb push_back
using namespace std;

const int MAXN = 1005;
const int MAX_S = (int)1e4 + 5;
const long long INF_LL = (long long)1e16;

struct Block {
    int w, s, v;

    Block() {}
    Block(int w, int s, int v):w(w), s(s), v(v) {}
};


long long dp[MAXN][2 * MAX_S];
vector<Block> blocks;

bool operator<(const Block& a, const Block& b) {
    return a.w + a.s > b.w + b.s;
}

int main(void) {
    int n;
    int w, s, v;

    scanf(" %d", &n);
    for (int i = 1; i <= n; i++) {
        scanf(" %d %d %d", &w, &s, &v);
        blocks.pb(Block(w, s, v));
    }

    sort(blocks.begin(), blocks.end());
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < MAX_S; j++) {
            if (i > 0) dp[i][j] = dp[i - 1][j];
            if (j <= blocks[i].s) dp[i][j] = max(dp[i][j], 1LL * blocks[i].v);

            if (i > 0 && j - blocks[i].w >= 0) {
                dp[i][min(j - blocks[i].w, blocks[i].s)] = max(dp[i][min(j - blocks[i].w, blocks[i].s)], blocks[i].v + dp[i - 1][j]);
            }
        }
    }

    long long ans = 0;
    for (int j = 0; j < MAX_S; j++) {
        ans = max(ans, dp[n - 1][j]);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 155264
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef pair<int, vector<int> > piv;
int d[4] = {-4, -1, 1, 4};

int main(int argc, char *argv[]){
  vector<int> a(8);
  for (int i = 0; i < 8; i++) {
    a[i] = i;
  }
  map<vector<int>, int> hash;
  hash[a] = 0;
  queue<piv> que;
  que.push(mp(0, a));
  while(!que.empty()){
    int len = que.front().first;
    vector<int> puzzle = que.front().second;
    que.pop();
    int pos;
    for (int i = 0; i < 8; i++) {
      if(puzzle[i] == 0){
        pos = i;
        break;
      }
    }
    for (int j = 0; j < 4; j++) {
      if(pos + d[j] < 0 || pos + d[j] >= 8)continue;
      if(abs((pos + d[j])%4 - pos%4) > 1)continue;
      swap(puzzle[pos], puzzle[pos + d[j]]);
      if(hash.find(puzzle) == hash.end()){
        hash[puzzle] = len + 1;
        que.push(mp(len + 1, puzzle));
      }
      swap(puzzle[pos], puzzle[pos + d[j]]);
    }
  }

  while(cin >> a[0]){
    for (int i = 1; i < 8; i++) {
      cin >> a[i];
    }
    std::cout << hash[a] << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll n, m;
  cin >> n >> m;
  
  ll ans = 0;
  ll sum = 0;
  map<ll,ll> s;
  s[0]++;
  for (int i = 0; i < n; i++){
    ll a;
    cin >> a;
    
    sum = (sum + a) % m;

    ans += s[sum];
    s[sum]++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7332
fun main(args: Array<String>) {
    abc066c()
}

// nが奇数の場合は奇数indexが右、そうでない場合は逆
fun abc066c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toLong() }.toLongArray()

    val (evenPairs, oddPairs) = aList.mapIndexed { index, l -> Pair(index, l) }.partition { it.first % 2 == 0 }

    val evens = evenPairs.map { it.second }.toLongArray()
    val odds = oddPairs.map { it.second }.toLongArray()

    val aListSizeIsEven = n % 2 == 0
    val left = if (aListSizeIsEven) odds.reversed().toLongArray() else evens.reversed().toLongArray()
    val right = if (aListSizeIsEven) evens else odds

    val answer = left + right

    println(answer.joinToString(separator = " "))
}


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

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long
#define vi vector<int>

int main(){
    LL a,b,c,d;
  	string s;
  
  	cin >> a >> b >> c >> d;
  
  	if(a+b > c+d) s="Left";
  	else if (a+b < c+d) s = "Right";
  	else s = "Balanced";
  
  	cout << s << endl;
  
    return 0;
}

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

int queen_in_rows[8];
bool col_free[8], upward_free[15], downward_free[15];
bool can_change[8];

void print_board() {
	int i, j;
	for (i = 0; i < 8; i++) {
		for (j = 0; j < queen_in_rows[i]; j++)
			printf(".");
		printf("Q");
		for (j = queen_in_rows[i] + 1; j < 8; j++)
			printf(".");
		printf("\n");
	}
}

void solution() {
	stack<pair<int, int> > S;
	pair<int, int> P;
	int row, col;
	S.push(make_pair(0, 0));
	while (1) {
		P = S.top();	S.pop();
		row = P.first;
		col = P.second;
		// 如果全部处理完了, 退出
		if (row == 8) break;
		// 如果当前行输入中已给出, 直接处理下一行
		if (!can_change[row]) {
			// cout << "can't change line " << row << endl;
			S.push(make_pair(row + 1, 0));
			continue;
		}
		// 如果该行之前放置过皇后, 那么将该皇后拿起, 然后查找位置从下一列开始
		if (queen_in_rows[row] != -1) {
			queen_in_rows[row] = -1;
			col_free[col] = true;
			upward_free[row + col] = true;
			downward_free[row - col + 7] = true;
			col++;
		}
		// 尝试寻找可以放置皇后的位置
		while (col < 8) {
			if (col_free[col] && upward_free[row + col] 
					&& downward_free[row - col + 7])
				break;
			col++;
		}
		// 如果没有找到, 则返回上一行处理
		if (col == 8) 
			continue;
		// 如果找到了, 则将皇后放入
		// cout << "line " << row << " put queen in " << col << endl;
		queen_in_rows[row] = col;
		col_free[col] = false;
		upward_free[row + col] = false;
		downward_free[row - col + 7] = false;
		// 保存当前行的信息, 然后查找下一行
		S.push(make_pair(row, col));
		S.push(make_pair(row + 1, 0));
	}
	while (!S.empty())
		S.pop();
	print_board();
}

int main(void) {
	int i, k, row, col;
	for (i = 0; i < 8; i++) {
		queen_in_rows[i] = -1;
		col_free[i] = true;
		upward_free[i] = true;
		downward_free[i] = true;
		can_change[i] = true;
	}
	for (i = 8; i < 15; i++) {
		upward_free[i] = true;
		downward_free[i] = true;
	}
	scanf("%d", &k);
	while (k--) {
		scanf("%d %d", &row, &col);
		queen_in_rows[row] = col;
		can_change[row] = false;
		col_free[col] = false;
		upward_free[row + col] = false;
		downward_free[row - col + 7] = false;
	}
	solution();
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define int long long int
#define MOD 1000000007
using namespace std;
int getindex(int num, int a[], int n) {
        for(int i=0;i<n;i++) {
                if(a[i] == num)
                        return i;
        }
        return -1;
}
void solve() {
        int n;
        cin >> n;
        int a[n], b[n], c[n];
        int sum = 0;
        for(int i=0;i<n;i++)
                cin >> a[i];
        for(int i=0;i<n;i++) {
                cin >> b[i];
//              sum += b[i];
        }
        for(int i=1;i<=n-1;i++)
                cin >> c[i];
        for(int i=0;i<n;i++) {
                sum += b[i];
                if(a[i+1] == a[i] + 1)
                        sum += c[a[i]];
        }
        cout << sum << endl;
        return ;
}

int32_t main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        solve();
        return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var nums [][][]int // nums[n][d] = n 桁、最初の数字 d の lunlun index 列
var lun []int      // lun[i] = lunlun index i の実際の数字

func main() {
	var K int
	fmt.Scanf("%d", &K)
	nums = make([][][]int, 11)
	lun = make([]int, 100001)
	fmt.Println(solve(K))
}

func solve(K int) int {
	nums[1] = make([][]int, 10)
	for i := 0; i <= 9; i++ {
		lun[i] = i
		nums[1][i] = []int{i}
	}

	if K <= 9 {
		return lun[K]
	}

	i := 10
	for n := 2; ; n++ {
		nums[n] = make([][]int, 10)

		for d := 1; d <= 9; d++ {
			nums[n][d] = []int{}

			for n2 := 1; d == 1 && n2 <= n-2; n2++ {
				if n2 == 1 {
					nums[n][d] = append(nums[n][d], i)
					lun[i] = d*int(math.Pow(10, float64(n-1))) + lun[0]

					if i == K {
						return lun[i]
					}

					i++
				}

				for _, i2 := range nums[n2][1] {
					nums[n][d] = append(nums[n][d], i)
					lun[i] = d*int(math.Pow(10, float64(n-1))) + lun[i2]

					if i == K {
						return lun[i]
					}

					i++
				}
			}

			for d2 := d - 1; d2 <= d+1; d2++ {
				if d2 < 0 || d2 > 9 {
					continue
				}

				for _, i2 := range nums[n-1][d2] {
					nums[n][d] = append(nums[n][d], i)
					lun[i] = d*int(math.Pow(10, float64(n-1))) + lun[i2]

					if i == K {
						return lun[i]
					}

					i++
				}
			}
		}
	}
}


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

int z(int x){
	if(x<0)return -x;
	return x;
}

int main(){
while(1){
	int d,n,m,in,ans=0,k=0;
	vector<int> D,K;
	scanf("%d",&d);
	if(d==0)break;
	scanf("%d%d",&n,&m);
	D.push_back(0); D.push_back(d); D.push_back(1000000000+2);
	for(int i=0;i<n-1;i++){
		scanf("%d",&in);
		D.push_back(in);
	}
	for(int i=0;i<m;i++){
		scanf("%d",&in);
		K.push_back(in);
	}
	sort(D.begin(),D.end());
	sort(K.begin(),K.end());
	for(int i=0;i<m;i++){
		while((D[k]+D[k+1])/2<K[i])k++;
		ans+=z(K[i]-D[k]);
	}
	printf("%d\n",ans);
}
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  int c;
  int i;
  cin>>a;
  cin>>b;
  for(i=0;i<2;i++){
    if(a > b){
      c+=a;
      a--;
    } else {
      c+=b;
      b--;
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
str = gets.strip

cnt = Hash.new
cnt['N'] = 0
cnt['S'] = 0
cnt['E'] = 0
cnt['W'] = 0
str.size.times { |i|
  cnt[str[i]] += 1
}

if ((cnt['N'] > 0) && (cnt['S'] == 0) ||
    (cnt['N'] == 0) && (cnt['S'] > 0) ||
    (cnt['E'] > 0) && (cnt['W'] == 0) ||
    (cnt['E'] == 0) && (cnt['W'] > 0))
  puts "No"
else
  puts "Yes"
end 


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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  s[k-1] += 'a' - 'A';

  cout << s << endl;
  return 0;
}


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

typedef   long long  int ll;
typedef  long double ld;
typedef std::vector<ll> vi;
typedef std::vector<std::vector<ll> > vv;

#define MOD 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,b) for(i=a;i<b;i++)
#define mp make_pair
#define pb(x) push_back(x)
#define fi first
#define se second
#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;
#define all(a) a.begin(),a.end()
#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];
#define ms(a,val) memset(a,val,sizeof(a))
using namespace std;

const int N1 = 1e2 + 5;
const int N = 1e5 + 5;
bool possible[N][N1];
ll dp[N][N1],v[N1],w[N1];
ll n;
ll func(ll val, ll i)
{
	if(val<=0)
	 return 0;
	if(i==(n+1))
	return INT_MAX;
	if(possible[val][i])
	return dp[val][i];
	possible[val][i] = true;
	dp[val][i] = min(func(val,i+1),w[i] + func(val - v[i],i+1));
	return dp[val][i]; 
	
	
}

void solve(){
            ll i,j,W;
            cin>>n>>W;
            //ll w[n+1]={0},v[n+1]={0};
            fo(i,1,n+1)
            {
				cin>>w[i]>>v[i];
			}
			//ll dp[n+1][W+1];
			ll v_max = 0;
			fo(i,1,n+1)
			v_max+=v[i];//,w_max+=w[i];
			
			
			
			for(i = v_max;i>=0;i--)
			{
				if(func(i,1)<=W)
				{
					cout<<i<<endl;
					break;
				}
			}
			









}

int main()
{
    IO;
      ll t=1,i;
      //cin>>t;


      while(t--)
      {

          solve();
      }
    return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

using P = tuple<ll, int, int>;

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

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

    int h, w; cin >> h >> w;
    int ch, cw, dh, dw; cin >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    vector<string> s(h);
    for (int i = 0; i < h; i++) cin >> s[i];

    vector<vector<ll>> dist(h, vector<ll>(w, linf));
    priority_queue<P, vector<P>, greater<P>> q;

    dist[ch][cw] = 0;
    q.emplace(0, ch, cw);
    while (!q.empty()) {
        auto [d, y, x] = q.top(); q.pop();
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w || s[ny][nx] == '#') continue;

            if (dist[ny][nx] > d) {
                dist[ny][nx] = d;
                q.emplace(d, ny, nx);
            }
        }
        for (int i = -2; i <= 2; i++) {
            int ny = y + i;
                if (ny < 0 || ny >= h) continue;
            for (int j = -2; j <= 2; j++) {
                int nx = x + j;
                if (nx < 0 || nx >= w || s[ny][nx] == '#') continue;
                
                if (dist[ny][nx] > d + 1) {
                    dist[ny][nx] = d + 1;
                    q.emplace(d + 1, ny, nx);
                }
            }
        }
    }
    cout << (dist[dh][dw] < linf ? dist[dh][dw] : -1) << endl;
    return 0;
}


Measured memory_bytes: 12524
#include <iostream>

using namespace std;
long long a[150];
long long gcd(long long a,long long  b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    long long   num=a[0];
    for(int i=0; i<n-1; i++)
    {
        long long  x=num;
        long long   y=a[i+1];
        long long  g=gcd(x,y);
        num=x/g*y/g*g;
    }
    cout<<num<<endl;
    //cout << "Hello world!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

bool isOk(int key,int value){
  return value >= key;
}

int binary_search(vector<int> a,int key){
  int ok = a.size();
  int ng = -1;

  while(abs(ok - ng) > 1){
    int mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<ll> a(n);rep(i,n)cin>>a[i];
  vector<ll> sums(n);rep(i,n)sums[i] = a[i];
  ll sum = SUM(a);

  for(int i = 1;i < n;++i){
    sums[i] += sums[i-1];
  }

  ll mini = 1000000000000;
  rep(i,n){
    mini = min(abs(abs(abs(sum - sums[i]) - abs(sums[i]))),mini);
  }

  ll ans = mini;
  print(ans);
  return 0;
} 


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
typedef pair<ll,ll> Pair;
 
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
 
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=400000;
 
ll n;
ll b0[62],b1[62];
ll a[MAX_N];
 
void twoadic(ll v){
    ll b=(1LL<< 59);
    for(ll i=0;i<=59;i++){
        if(v/b>0) {
            b1[59-i]++;
            v-=b;
        }
        else b0[59-i]++;
        b/=2;
    }
}
 
void solve(){
    rep(i,n){
        twoadic(a[i]);
    }
    ll ans=0;
    rep(i,60){
        ll pl=(1LL<<i)%MOD*b0[i];
        pl%=MOD;
        pl*=b1[i];
        pl%=MOD;
        ans+=pl;
        ans%=MOD;
    }
    cout << ans << endl;
}
 
int main(){
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,60){
        b0[i]=0;b1[i]=0;
    }
    solve();
}


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

using namespace std;
typedef pair<int, int> P;
// input


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
    int N;
    cin >> N;
    N = N % 1000;
    if(N == 0) cout << N << endl;
    else cout << 1000 - N << endl;
}

Measured memory_bytes: 3640
use proconio::{fastout, input, marker::Chars, marker::Usize1};
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        ch: Usize1,
        cw: Usize1,
        dh: Usize1,
        dw: Usize1,
        mut s: [Chars; h],
    }

    let mut q = VecDeque::new();
    q.push_back((ch, cw));

    let mut costs = vec![vec![-1; w]; h];
    costs[ch][cw] = 0;

    while !q.is_empty() {
        if let Some((y, x)) = q.pop_front() {
            for dx in -1..=1 {
                for dy in -1..=1 {
                    if i64::abs(dx) == i64::abs(dy) {
                        continue;
                    }
                    let nx = x as i64 + dx;
                    let ny = y as i64 + dy;
                    if nx < 0 || nx >= w as i64 || ny < 0 || ny >= h as i64 {
                        continue;
                    }
                    let nx = nx as usize;
                    let ny = ny as usize;
                    if s[ny][nx] != '#' && (costs[ny][nx] == -1 || costs[ny][nx] > costs[y][x]) {
                        costs[ny][nx] = costs[y][x];
                        q.push_front((ny, nx));
                    }
                }
            }
            for dx in -2..=2 {
                for dy in -2..=2 {
                    let nx = x as i64 + dx;
                    let ny = y as i64 + dy;
                    if nx < 0 || nx >= w as i64 || ny < 0 || ny >= h as i64 {
                        continue;
                    }
                    let nx = nx as usize;
                    let ny = ny as usize;
                    if s[ny][nx] != '#' && (costs[ny][nx] == -1 || costs[ny][nx] > costs[y][x] + 1)
                    {
                        costs[ny][nx] = costs[y][x] + 1;
                        q.push_back((ny, nx));
                    }
                }
            }
        }
    }
    println!("{}", costs[dh][dw]);
}


Measured memory_bytes: 11160
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 10000000000000
int main()
{
      int n,m,d[1005],c[1005];
      long long dp[1005][1005];
      cin >> n >> m;
      for(int i = 0; i < n;i++)cin >> d[i];
      for(int i = 0; i < m;i++)cin >> c[i];
      for(int i = 0;i <= m;i++)for(int j = 0;j<=n;j++)dp[i][j] = INF;
      dp[0][0] = 0;
      for(int i = 0; i < m;i++)
      {
            for (int j = 0;j <= n;j++)
            {
                  if(dp[i][j]!=INF)
                  {
                        dp[i+1][j] = min(dp[i][j],dp[i+1][j]);
                        dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+d[j]*c[i]);
                  }
            }
      }
      cout << dp[m][n] << endl;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;
const long long MOD = 1000000007LL;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){

    int n;
    cin >> n;

    float a[n];
    FOR(i, n){
        cin >> a[i];
    }

    sort(a, a + n);
    //sort(ALL(a));

    float ans = (a[0] + a[1])/2;
    FORR(i, 2, n){
        ans = (ans + a[i])/2;
    }

    cout << ans;

    return 0;
}




Measured memory_bytes: 256
def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

def ans():
  N, X = map(int,input().split())
  x = list(map(int,input().split()))
  xx = [abs(X-n) for n in x]
  res = xx[0]
  for i in range(1,N):
    res = gcd(res, xx[i])
  print(res)
ans()

Measured memory_bytes: 14252
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
ll power(int a,int b){
	int sum=1;
	for (; b; b>>=1){
		if (b&1)	sum=1ll*sum*a%MOD;
		a=1ll*a*a%MOD;
	}
	return sum;
}
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int m,n;
  cin >> m >> n;
  cout << power(m,n) << endl;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;

int main() {
  ll N,K;
  cin>>N>>K;
  ll a[N+10];
  ll cheak[N+10];
  for(int i=1;i<N+1;i++){
    cin>>a[i];
    cheak[i]=0;
  }
  ll king=1;
  cheak[1]=0;
  ll F,S;
  for(int i=1;i<=N*10;i++){
    king=a[king];
    if(cheak[king]!=0){
      F=cheak[king];
      S=i-F;
      break;
    }
    cheak[king]=i;
  }
  ll c=0;
  if(K>F){
    K-=F;
    c=1;
    K%=S;
    K+=F;
  }
  
  king=1;
  for(int i=0;i<K;i++){
    king=a[king];
  }
  cout<<king;
  
}


Measured memory_bytes: 6708
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	s <- getLine
	t <- getLine
	putStrLn $ which "YES" "NO" $ s == reverse t


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


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

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int i;
    ll sumi=0,x,y;
    rep(i,n){
    	cin>>x>>y;
    	sumi+=y-x+1;
    }
    cout<<sumi<<endl;
    return 0;  
    
}



Measured memory_bytes: 256