akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>

int main(){
  int n, min, max;
  long long sum;
  //std::vector<int> v;
  std::cin >> n;
  int v[n];

  for(int i = 0; i < n; i++){
    std::cin >> v[i];

  }
  min = v[0];
  max = v[0];
  sum = 0;
   for(int j = 0; j < n; j++){
     if (v[j] < min) {
       min = v[j];
     }
     if (max < v[j]) {
       max = v[j];
     }
     sum += v[j];
   }
   std::cout << min << " " << max << " " << sum << std::endl;
   return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read() {
	ll x=0;
	int f=1;
	char c=getchar();
	for(; !isdigit(c); c=getchar()) if(c=='-')f=-f;
	for(; isdigit(c); c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x) {
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,d[2022],g[2022][2022];
string s;
ll dfs(int l,int r) {
	if(r-l<=1)return 0;
	int mid=(l+r)/2,x=0,y=1;
	memset(d,0,sizeof(d));
	for(int i=mid-1; i>=l; i--) {
		x=(x+y*(s[i]-'0'))%2019;
		d[x]++;
		y=y*10%2019;
	}
	x=0;
	y=1;
	ll ret=0;
	fo(i,mid,r) {
		x=(x*10+(s[i]-'0'))%2019;
		y=y*10%2019;
		ret+=d[g[y][x]];
	}
	return ret+dfs(l,mid)+dfs(mid,r);
}
int main() {
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>s;
	n=s.size();
	fo(i,0,2020){
		g[i][0]=0;
		fo(j,0,2020) if((i*j+1)%2019==0){
			g[i][1]=j;
			break;
		}
		fo(j,2,2020)g[i][j]=(g[i][j-1]+g[i][1])%2019;
	}
	cout<<dfs(0,n)<<endl;
	return 0;
}


Measured memory_bytes: 19680
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	long long n, Y,x,y,z=0;
	cin >> n >> Y;
	for (z= 0; z <= n; z++) {
		for (y = 0; y <= n-z; y++) {
			x = n - z - y;
			if (z>=0&&10000 * x + 5000 * y + 1000 * z == Y ) {
				cout << x << " " << y << " " << z << endl;
				exit(0);
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, x;
  cin >> n >> x;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long res = 0;
  for (long long i = 1; i < n; i++) {
    if (a[i - 1] + a[i] > x) {
      res += a[i] + a[i - 1] - x;
      if (a[i - 1] > x) {
        a[i] = 0;
        a[i - 1] = x;
      } else {
        a[i] = x - a[i - 1];
      }
    }
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(i,x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
    ll f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//******head by yjjr******
const int maxn=5e3+6;
int n,p[maxn];
ll f[maxn][maxn],A,B;
int main(){
    n=read(),A=read(),B=read();
    rep(i,1,n){int x=read();p[x]=i;}
    mem(f,0x20);
    f[0][0]=0;
    rep(i,1,n+1)rep(j,0,i)
        if(p[i]>p[j]){
            f[i][i]=min(f[i][i],f[i-1][j]);
            f[i][j]=min(f[i][j],f[i-1][j]+B);
        }else f[i][j]=min(f[i][j],f[i-1][j]+A);
    cout<<*min_element(f[n],f[n]+n+1)<<endl;
    return 0;
}

Measured memory_bytes: 196096
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

using Plc = pair<ll, char>;
map<ll, vector<Plc>> xmap, ymap, upmap, downmap;
ll N;

int main() {
  //
  cin >> N;
  rep(i, 0, N) {
    ll x, y;
    char u;
    cin >> x >> y >> u;
    xmap[x].push_back(Plc(y, u));
    ymap[y].push_back(Plc(x, u));
    upmap[x - y].push_back(Plc(x, u));
    downmap[x + y].push_back(Plc(x, u));
  }

  ll ans = INF;

  for (auto e : xmap) {
    auto v = e.second;
    if (v.size() < 2) continue;

    sort(v.begin(), v.end());
    ll cu = -INF;
    for (auto p : v) {
      if (p.second == 'U') {
        cu = p.first;
      } else if (p.second == 'D' && cu != -INF) {
        chmin(ans, (p.first - cu) * 5);
      }
    }
  }

  for (auto e : ymap) {
    auto v = e.second;
    if (v.size() < 2) continue;

    sort(v.begin(), v.end());
    ll cr = -INF;
    for (auto p : v) {
      if (p.second == 'R') {
        cr = p.first;
      } else if (p.second == 'L' && cr != -INF) {
        chmin(ans, (p.first - cr) * 5);
      }
    }
  }

  for (auto e : upmap) {
    auto v = e.second;
    if (v.size() < 2) continue;

    sort(v.begin(), v.end());
    ll cu = -INF;
    ll cr = -INF;
    for (auto p : v) {
      if (p.second == 'U') {
        cu = p.first;
      } else if (p.second == 'R') {
        cr = p.first;
      } else if (p.second == 'L' && cu != -INF) {
        chmin(ans, abs(p.first - cu) * 10);
      } else if (p.second == 'D' && cr != -INF) {
        chmin(ans, abs(p.first - cr) * 10);
      }
    }
  }

  for (auto e : downmap) {
    auto v = e.second;
    if (v.size() < 2) continue;

    sort(v.begin(), v.end());
    ll cd = -INF;
    ll cr = -INF;
    for (auto p : v) {
      // cout << p.first << " " << p.second << endl;
      if (p.second == 'D') {
        cd = p.first;
      } else if (p.second == 'R') {
        cr = p.first;
      } else if (p.second == 'L' && cd != -INF) {
        chmin(ans, abs(p.first - cd) * 10);
      } else if (p.second == 'U' && cr != -INF) {
        chmin(ans, abs(p.first - cr) * 10);
      }
    }
  }

  if (ans == INF) {
    cout << "SAFE";
    return 0;
  }

  cout << ans;
}


Measured memory_bytes: 77388
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif

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

	ll n, k;
	cin >> n >> k;
	ll arr[n + 1];
	for (ll i = 1; i <= n; i++)
	{
		cin >> arr[i];
	}

	if (k <= n)
	{
		ll a = 1;
		for (ll i = 1; i <= k; i++)
		{
			a = arr[a];
		}
		cout << a;
		return 0;
	}
	bool vis[200005];
	int cnt[200005];
	memset(vis, false, sizeof(vis));
	memset(cnt, 0, sizeof(cnt));

	ll b = 1;
	vis[1] = true;
	cnt[1] = 0;
	ll cycle;
	ll sub;
	for (ll i = 1; i <= n; i++)
	{
		b = arr[b];
		if (vis[b])
		{
			cycle = i - cnt[b];
			sub = cnt[b];
			break;
		}
		else
		{
			vis[b] = true;
			cnt[b] = i;
		}
	}
	k -= sub;
	k %= cycle;

	if (k <= n)
	{
		for (ll i = 1; i <= k; i++)
		{
			b = arr[b];
		}
		cout << b;
		return 0;
	}

	return 0;




}



Measured memory_bytes: 6184
#include<stdio.h>                                                 
                                                                  
int main(void){                                                   
   int N,K,i,j;                                                   
   scanf("%d %d",&N,&K);                                          
   int d[N];                                                      
                                                                  
   for(i = 0; i < K; i++){                                        
      int m;                                                      
      scanf("%d",&m);                                             
      for(j = 0; j < m; j++){                                     
         int a;                                                   
         scanf("%d",&a);                                          
         d[a-1]=1;                                                
      }                                                           
   }                                                              
   int cnt = 0;                                                   
   for(i = 0; i < N;i++){                                         
      if(d[i] == 1){                                              
         cnt++;                                                   
      }                                                           
   }                                                              
    printf("%d",N-cnt);                                           
   return 0;                                                      
                                                                  
}     

Measured memory_bytes: 1728
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

bool prime[2000001];
void create_prime() {
	REP(i, 2, 2000001) prime[i] = true;

	for (int i = 2; i * i < 2000001; i++) {
		for (int j = 2 * i; j < 2000001; j += i) {
			prime[j] = false;
		}
	}
	return;
}
int main() {
	int N, P;
	create_prime();
	
	while (cin >> N >> P, N != -1 && P != -1) {
		vector<int> v, sum;
		REP(i, N + 1, 2000001) {
			if (prime[i]) v.push_back(i);
			if (v.size() > 2 * P + 1) break;
		}

		REP(i, 0, v.size()) {
			REP(j, i, v.size()) {
				sum.push_back(v[i] + v[j]);
			}
		}

		sort(sum.begin(), sum.end());
		cout << sum[P - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 5216
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
string s,t,u;
int main(){
        while(cin>>s>>t){
                VgetII(a,b);
                cin>>u;
                if(s==u) a--;
                else b--;
                printf("%d %d\n",a,b);
        }
}

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

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

int main() {
  int N; cin >>N;
  vector<string> s(N);
  map<string,ll> a;
  rep(i,0,N) {
    cin >>s[i];
    sort(s[i].begin(),s[i].end());
    a[s[i]]++;
  }
  ll ans=0;
  for (auto p : a) {
    auto v=p.second;
    ans+=v*(v-1)/2;
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 14020
#include <iostream>
using namespace std;
#define forr(i,m,n) for (int i=(m); i<=(n); i++)
#define DBG 0

#define MAXN 3001
string z[MAXN][MAXN];

int main() {
  size_t ns, nt;
  int cnt;
  string s, t, str;
  cin >> s >> t;
  ns = s.size();
  nt = t.size();
  if (DBG) { cout << "s:" << s << " t:" << t
                << " nst:" << ns << " " << nt << endl;
          }
  str = "";
  forr(j,0,nt-1) {
    if (s[0] == t[j])
      str = string(1, s[0]);
    z[0][j] = str;
  }
  forr(i,1,ns-1) {
    z[i][0] = (s[i] == t[0] ? string(1, s[i]) : "");
    forr(j,1,nt-1) {  int s1, s2, s3;
      s1 = z[i-1][j].size();
      s2 = z[i][j-1].size();
      s3 = z[i-1][j-1].size() + (s[i] == t[j] ? 1 : 0);
      if (s1 >= s2 && s1 >= s3)
        z[i][j] = z[i-1][j];
      else  if (s2 >= s1 && s2 >= s3)
          z[i][j] = z[i][j-1];
      else
        z[i][j] = z[i-1][j-1] + (s[i] == t[j] ? string(1, s[i]) : "");
    }
  }
  cout << z[ns-1][nt-1];
}


Measured memory_bytes: 841472
#include<bits/stdc++.h>
int main() {
    int a, b;
    std::cin >> a >> b;
    if(a <= 0 && b >= 0) {
        std::cout << "Zero" << std::endl;
    } else if(a > 0 && b > 0) {
        std::cout << "Positive" << std::endl;
    } else if( (b-a)%2 != 0 ) {
        std::cout << "Positive" << std::endl;
    } else {
        std::cout << "Negative" << std::endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>  // std::unique
#include <cmath>
using namespace std;

using ll = long long;
constexpr auto PrimeBigNum10_9_7 = 1000000007;

// 素数判定
template <typename T>
bool IsPrimeNumber(T value) {

	for (int i = 2; i * i <= value; ++i) {
		if ((value % i) == 0) {
			return true;
		}
	}
	return false;
}

// 桁数判定
template <typename T>
T GetFigureLength(T value) {
	T figure = 1;
	while (value >= 10) {
		value /= 10;
		++figure;
	}
	return figure;
}

// 素因数分解結果
template <typename T>
map<T, T> GetPrimeFactorize(T value) {

	map<T, T> res;

	for (T i = 2; i * i <= value; ++i) {
		if ((value%i) != 0)	continue;

		T count = 0;
		while ((value % i) == 0) {
			value /= i;
			++count;
		}

		res[i] = count;
	}

	if (value != 1) {
		res[value] = 1;
	}
	return res;
}


void dfs(int i, const int size, const int range_start, const int range_end, vector<int> &buf, vector<vector<int>>&result)
{
	if (i == size) {
		result.push_back(buf);
	}
	else {
		// a[i-1]<=a[i]の条件判定
		int rs = range_start;
		if (i > 0) {
			rs = buf[i - 1];
		}
		//

		for (int j = rs; j <= range_end; ++j) {
			buf[i] = j;
			dfs(i + 1, size, range_start, range_end, buf, result);
		}
	}
}


struct Data {
	ll a, b, c, d;
};

int calcScore(const vector<int>& vec, const Data& data) {
	auto ans = vec.at(data.b-1) - vec.at(data.a-1);

	if (ans == data.c)	return data.d;
	return 0;
}

int main(void) {
	ll n, m, q;
	vector<Data> datas;


	cin >> n >> m >> q;
	for (int i = 0; i < q; ++i) {
		Data d;
		cin >> d.a >> d.b >> d.c >> d.d;
		datas.push_back(d);
	}


	ll size = n;
	ll range_start = 1;
	ll range_end = m;

	vector<int> buf(size);
	vector<vector<int>> result;
	dfs(0, size, range_start, range_end, buf, result);

	ll ansMax = 0;
	for (ll i = 0; i < result.size(); ++i) {

		const auto& v = result[i];


		ll score = 0;

		for (auto itr = datas.begin(); itr != datas.end(); ++itr) {
			score += calcScore(v, *itr);
		}
/*
		for (int j = 0; j < v.size(); ++j) {
			cout << v[j] << " ";
		}

		
		cout << "=" << score << endl;*/

		ansMax = max(ansMax, score);
	}
	auto output = ansMax;
	cout << output;

	return 0;
}

Measured memory_bytes: 9872
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    c = [list(mi()) for i in range(3)]
    if c[0][0]+c[1][1] == c[0][1]+c[1][0] \
        and c[1][1]+c[2][2] == c[1][2]+c[2][1] \
        and c[2][2]+c[0][0] == c[2][0]+c[0][2]:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


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

int find_par(int i,int par[])
{
	if(i==par[i])
		return i;
		
	return par[i]=find_par(par[i],par);
}

int main()
{
	int n;
	cin>>n;
	
	vector<pair<int,int> > v;
	
	int x[n],y[n];
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i],v.push_back({x[i],i});
		
	sort(v.begin(),v.end());
	
	int arr[n];
	for(int i=0;i<n;i++)
		arr[i]=y[v[i].second];
		
	int par[n];
	int sz[n];
	
	for(int i=0;i<n;i++)
		par[i]=i,sz[i]=1;
		
	
	stack<int> s;
	
	for(int i=0;i<n;i++)
	{
		int mi=-1;
		if(s.size())
			mi=s.top();
			
		while(s.size() && arr[s.top()]<arr[i])
		{
		//	cout<<arr[s.top()]<<' '<<i<<endl;
			
			int b=find_par(s.top(),par);
			
			if(b!=i)
			{
				par[b]=i;
				sz[i]+=sz[b];
			}
			
			s.pop();
		}
		
		if(mi==-1 || arr[i]<arr[mi])
		{
			s.push(i);
		}
		else
		{
			s.push(mi);
		}
	}
	
	
	
	int ans[n];
	
	for(int i=0;i<n;i++)
	{
		int a=find_par(i,par);
		ans[v[i].second]=sz[a];	
	}
	
	for(int i=0;i<n;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 12724
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int X, Y;
	cin >> X >> Y;
	cout << X + Y / 2 << endl;

	return(0);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char s[100],t[100];
    int i;
    gets(s);
    for(i=0;i<strlen(s);i++)
        t[i]='x';
    t[i]='\0';
    puts(t);
    return 0;
}


Measured memory_bytes: 128
from operator import mul
from functools import reduce

def cmb(n,r):
    if n < r: return 0
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
n, k = map(int, input().split())
inf = 10 **9 + 7
for i in range(1, k+1):
    print(cmb(n-k+1, i)*cmb(k-1, i-1)%inf)



Measured memory_bytes: 3944
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long [] in = new long [1000000];
        
        for(int i=1;i<100;i++){for(int j=1;j<100;j++){
          for(int k=1;k<100;k++){in[i*i+j*j+k*k+i*j+j*k+k*i-1]++;}                                                                                                                                                                                  
                                             }                                                                            
                                          }                         
         for(int i=0;i<n;i++){System.out.println(in[i]);}	
	}
}

Measured memory_bytes: 46548
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long[] A = new long[N];

        for (int i = 0; i < N; i++) {
            A[i] = Long.parseLong(sc.next());
        }

        long mod = 1000000007L;
        long ans = 0;
        long base = 1;
        for (int i = 0; i <= 60; i++) {
            long zeroNum = 0;
            long oneNum = 0;

            for (int j = 0; j < N; j++) {
                int bit = (int)((A[j] >> i) & 1);

                if (bit == 0) {
                    zeroNum++;
                } else {
                    oneNum++;
                }
            }

            ans += ((zeroNum % mod) * (oneNum % mod) % mod) * (base % mod) % mod;
            ans %= mod;
            base *= 2;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 66240
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;

int main(){
    cout << fixed << setprecision(6);
    int n ; cin >> n;
    double out ;
    out = (double)(n/2+n%2)/n;
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 3264
from collections import Counter
N = int(input())
a = [int(i) for i in input().split()]
for i in range(N):
    if a[i] % 4 == 0:
        a[i] = 0
    elif a[i] % 4 == 2:
        a[i] = 2
    else:
        a[i] = 1
counts = dict(Counter(a))
flag = False
if 1 in counts:
    if 0 in counts:
        if 2 in counts:
            if counts[0] >= counts[1]:
                flag = True
        
        else:
            if counts[0] == counts[1]-1:
                flag = True
        
else:
    if 2 in counts:
        if counts[2] >= 2:
            flag = True
        else:
            if 0 in counts:
                flag = True
                
    else:
        if 0 in counts:
            flag = True
                

    
print('Yes' if flag==True else 'No')
    


Measured memory_bytes: 62704
import math
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
input = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(input())
    a = [0]+list(map(int,input().split()))+[0]
    lc = [0 for i in range(n)]
    sum = abs(a[0]-a[1])
    for i in range(n):
        lc[i] = abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])-abs(a[i]-a[i+2])
        sum += abs(a[i+1]-a[i+2])
    for i in range(n):
        print(sum-lc[i])



if __name__ == '__main__':
    main()


Measured memory_bytes: 37892
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

int main(){
	ll n,k ;
	cin >> n >> k ;
	vll a(n),b(n) ;
	for(auto &i:a) cin >> i ;
	for(auto &i:b) cin >> i ;
	sort(all(a)) ;
	sort(all(b)) ;
	reverse(all(b)) ;
	ll l,r,m ;
	l = -1 ;
	r = 100000000000000 ;
	while(l+1<r){
		m = (l+r)/2 ;
		ll cnt = 0 ;
		for(int i=0;i<n;i++){
			ll sub = m/b.at(i) ;
			if(a.at(i)>sub) cnt += a.at(i)-sub ;
		}
		if(cnt<=k) r = m ;
		else l = m ;
	}
	cout << r << endl ;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb(a)   push_back(a)
#define fi first
#define se second
#define siz(v)  int(v.size())
#define nl cout<<"\n"
#define print(a,n) {for(i=0;i<n;i++)   {cout<<a[i]<<" ";}nl;}
#define ll long long int
using namespace std;

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

    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
	#endif*/
	ll x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y;
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

typedef int64_t int64;
typedef uint64_t uint64;
typedef std::bitset<64> bitset;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,k;
  cin>>n>>k;
  std::vector<uint64> a(n);
  for(int i = 0; i < n; ++i){
    cin>>a[i];
  }

  std::unordered_multiset<bitset> set;

  for(int l=0;l<n;l++){
    uint64 sum=0;
    for(int r=l;r<n;r++){
      sum+=a[r];
      set.insert(bitset(sum));
    }
  }

  for(int bi=62;bi>=0;bi--){
    int count=0;
    for(auto bs:set){
      if(bs[bi]) count++;
    }
    if(count>=k){
      std::unordered_multiset<bitset> new_set;
      for(auto itr=set.begin();itr!=set.end();itr++){
        if((*itr)[bi]){
          new_set.insert(*itr);
        }
      }
      set=new_set;
    }
  }

  if(set.size()==0){
    cout<<0<<endl;
  }else{
    uint64 result=UINT64_MAX;
    for(auto bs:set){
      result=result&bs.to_ulong();
    }
    cout<<result<<endl;
  }





  return 0;
}


Measured memory_bytes: 28444
#include<stdio.h>

#define N 500000
#define M 2000000000

int cnt=0, L[N/2+2], R[N/2+2];

void merge(int A[], int left, int mid, int right){
    int n1, n2, i, j;
    n1 = mid - left; n2 = right - mid;

    for(i=0 ; i<n1 ; i++)   L[i] = A[left+i];
    for(i=0 ; i<n2 ; i++)   R[i] = A[mid+i];
    
    L[n1] = R[n2] = M;
    i=0; j=0;

    for(int k=left ; k<right ; k++, cnt++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int A[], int left, int right){
    if(left+1<right){
        int mid = (left+right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}
int main(void){
    int n, S[500000];
    scanf("%d", &n);
    for(int i=0 ; i<n ; i++) scanf("%d", &S[i]);
    mergeSort(S, 0, n);
    for(int i=0 ; i<n ; i++)
        if(i==n-1)    printf("%d\n", S[i]);
        else            printf("%d ", S[i]);
    printf("%d\n",cnt);
    return 0;

}



Measured memory_bytes: 5608
N=int(input())
P=[0]*5
count=0
for i in range (5):
	P[i]=int(input())
for i in range (5):
	if P[i]>=N:
		count+=1
if count==5:
	print(5)
else:
	Q=sorted(P)
	if N%Q[0]==0:
		R=N//Q[0]
		print(R+4)
	else:
		R=N//Q[0]+1
		print(R+4)

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

/* macros */
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define inf 1e9;

int n;
vi nums;

int dp[100005];
int go(int pos){
    
    if (pos == n){
        return 0;
    }
    if (pos > n){
        return inf;
    }
    
    if (dp[pos] != -1){
        return dp[pos];
    }
    
    int ans = INT_MAX;
    int op1 = go(pos+1) + abs(nums[pos] - nums[pos+1]);
    int op2 = go(pos+2) + abs(nums[pos] - nums[pos+2]);
    
    ans = min(ans, min(op1,op2));
    
    return dp[pos] = ans;
}

void solve(){
    cin>>n;
    nums.clear();
    nums.resize(n+1);
    rep(i,1,n+1) cin>>nums[i];
    memset(dp, -1, sizeof dp);
    int ans = go(1);
    cout << ans << "\n";
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 9472
array = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]
x, y = map(int, input().split())
for i in range(len(array)):
    if x in array[i]:
        if y in array[i]:
            print('Yes')
            break
        else:
            print('No')
            break

Measured memory_bytes: 3060
/**
 *    author:  yoseph
 *    created: 27.07.2020 22:17:55      
**/
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y;
	cin >> x >> y;
	for (int i = 0; i <= x; ++i) {
		if (y == i*2 + (x - i)*4) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}


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

ll sums(ll n){
  ll ans = 0;
  for (ll i=1; i<=n; i++) ans += i;
  return ans;
}

// <がaコ、>がbコ並んでる
ll solve(ll a,ll b){
  if (a==0) return sums(b);
  if (b==0) return sums(a);
  if (a>=b) return sums(a) + sums(b-1);
  if (a<b)  return sums(a-1) + sums(b);
}

int main() {
  string s; cin >>s;
  ll n = s.size()+1;
  vector<ll> op; // <<<3>>>-3<<<3>>-2みたいな
  bool minus = false; //>が続いてるならtrue
  if (s.at(0) == '>'){
    op.push_back(0); minus = true;
  }
  ll buf = 0;
  for (ll i=0; i<n-1; i++){
    if (s.at(i)=='>' && minus) buf++;
    if (s.at(i)=='<' && !minus) buf++;
    if (s.at(i)=='>' && !minus){
      op.push_back(buf); buf = 1; minus = true;}
    if (s.at(i)=='<' && minus){
      op.push_back(buf); buf = 1; minus = false;}
  }
  op.push_back(buf);
  if (op.size()%2 != 0) op.push_back(0);
  /* 1.>が続いてて>が来たらカウント増やす
     2.<が続いてて<が来たらカウント増やす
     3.<が続いてて>が来たらそこまでのカウントをopに追加、
       カウントを1にして>が続いてるとする
     4.>が続いてて<が来たらそこまでのカウントをopに追加、
       カウントを1にして<が続いてるとする
  */
  /* 現時点でopには<の数、>の数が順に並んでる
     1 3 2 1 5 3 1 みたいな
     0 2 5 7 6 4 5 みたいな
     で、2コ区切りで見る。
     (1,3) (2,1) (5,3) (3,1)
  */
  ll a, b;
  ll ans = 0;
  for (ll i=0; i<op.size()/2; i++){
    a = op.at(i*2); b = op.at(i*2+1);
    ans += solve(a,b);
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n,a,b;cin>>n>>a>>b;
  if(a>b){
    cout<<0<<endl;
  }else if(a==b){
    cout<<1<<endl;
  }else{
    if(n==1){
      if(a!=b)cout<<0<<endl;
      else cout<<1<<endl;
    }else{
      cout<<(n-2)*(b-a)+1<<endl;
    }
  }
  return 0;
}


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

int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), c(n-1);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        int b;
        cin >> b;
        ans += b;
    }
    for(int i=0; i<n-1; i++){
        cin >> c[i];
    }

    for(int i=0; i<n-1; i++){
        if(a[i+1]-a[i] == 1){
            ans += c[a[i]-1];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N, W, w[100];
long long v[100], dp[100][100001];
int main(){
    scanf("%d%d", &N, &W);
    for(int i=0; i<N; i++) scanf("%d%d", v+i, w+i);
    for(int i=0; i<N; i++){
        for(int j=0; j<=W; j++){
            dp[i][j] = max(i!=0 ? dp[i-1][j] : 0LL, j>=w[i] ? (i!=0 ? dp[i-1][j-w[i]] : 0LL)+v[i] : 0LL);
        }
    }
    long long ans = 0;
    for(int i=0; i<=W; i++) ans = max(ans, dp[N-1][i]);
    printf("%lld\n", ans);
}


Measured memory_bytes: 11388
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;

class Program
{
    static readonly double INF = double.PositiveInfinity;

    static void Main(string[] args)
    {
        while (true)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = input[0], M = input[1], P = input[2], A = input[3] - 1, B = input[4] - 1;
            if (N == 0) break;
            int[] nums = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            double[][] dist = E.Range(0, M).Select(i => E.Repeat(INF, M).ToArray()).ToArray();

            for (int i = 0; i < P; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                dist[input[0] - 1][input[1] - 1] = input[2];
                dist[input[1] - 1][input[0] - 1] = input[2];
            }
            double[][] dp = E.Range(0, 1 << N).Select(i => E.Repeat(INF, M).ToArray()).ToArray();
            dp[0][A] = 0;
            for (int mask = 0; mask < (1 << N); mask++)
                foreach (int use in E.Range(0, N).Where(use => (mask >> use & 1) == 0))
                    for (int i = 0; i < M; i++)
                        for (int j = 0; j < M; j++)
                        {
                            double cost = dp[mask][i] + dist[i][j] / nums[use];
                            int nextMask = mask | 1 << use;
                            dp[nextMask][j] = Math.Min(dp[nextMask][j], cost);
                        }

            double ans = INF;
            for (int mask = 0; mask < (1 << N); mask++) ans = Math.Min(ans, dp[mask][B]);
            //E.Range(0, 1 << N).Min(mask => dp[mask][B]);
            Console.WriteLine((ans == INF) ? "Impossible" : ans.ToString("f3"));
        }
    }
}

Measured memory_bytes: 6404
#include <iostream>
#include <algorithm>
#include<string>
#include<vector>
#include<queue>
#include<utility>
int main() {
	int n;
	std::cin >> n;
	int an = 0;
	int han = 0;
	std::vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> v[i];
	}
	std::sort(v.begin(), v.end());
	for (int i = 0; i < n;) {
		int c = v[i], f = 0;
		while (i < n&&c == v[i]) {
			++f;

			++i;
		}
		an += f % 2;
	}
	std::cout << an << std::endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll p[406][406];
ll pre[406][406];
ll dp[406][406]={};
ll a[406],b[406];
int main()
{
    p[0][0]=1;
    for(ll i=1;i<=400;i++)
    {
        p[i][0]=1;
        pre[i][0]=1;
        for(ll j=1;j<=400;j++)
        {
            p[i][j]=(p[i][j-1]*i)%mod;
        }
    }
    for(ll i=1;i<=400;i++)
        for(ll j=0;j<=400;j++)
    {
        pre[i][j]=(pre[i-1][j]+p[i][j])%mod;
    }



    ll n,c;
    cin>>n>>c;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(ll i=1;i<=n;i++)
    {
        cin>>b[i];
    }

    dp[0][0]=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=0;j<=c;j++)
        {
            for(ll k=0;k<=j;k++)
            {
                ll y=(pre[b[i]][k]-pre[a[i]-1][k]+mod)%mod;
                dp[i][j]=(dp[i][j]+dp[i-1][j-k]*y)%mod;
                dp[i][j]%mod;
            }
        }
    }
    cout<<dp[n][c]%mod<<endl;
}


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


int main() {

  int N, ans;

  cin >> N;


  vector<int> L(100000);
  vector<int> R(100000);

  for ( int i = 0; i < N; i++ ) {
   cin >> L.at(i) >> R.at(i);
  }


 
  ans = 0;

  for ( int i = 0; i < N; i++ ) {
   ans += R.at(i) - L.at(i) +1;
  }
  

  cout << ans << endl;



}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	
	int N; cin >> N;
	vector<int> A(N+1);
	vector<int> B(N);

	REP(i,N+1) cin >> A[i];
	REP(i,N) cin >> B[i];

	ll ans = 0;
	REP(i,N){
		// A[i]体の全てのモンスターを倒せる
		if(A[i] <= B[i]){ 
			ans += A[i];
			B[i] -= A[i];
		}
		// 街iのモンスターをB[i]だけ倒せる
		else if(A[i] > B[i]){
			ans += B[i];
			B[i] = 0;
		}
		//まだ倒せそうなら街i+1も倒しておく
		if(B[i] > 0){
			if(A[i+1] <= B[i]){
				ans += A[i+1];
				A[i+1] = 0;
			}else{
				ans += B[i];
				A[i+1] -= B[i];
			}
		}
	}

	cout << ans << endl;




	return 0;

}


Measured memory_bytes: 1024
N, A, B = gets.strip.split.map(&:to_i)

def find_sum_of_digits(n)
  sum = 0
  while n > 0 do
    sum += n % 10
    n /= 10
  end
  sum
end

answer = (1..N).map{ |i| [i, find_sum_of_digits(i)] }.select { |d| A <= d[1] && d[1] <= B }.inject(0) { |sum, d| sum + d[0] }
puts answer

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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<pair<int, ll>>> g (n + 1);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        g[u].push_back({ v, w });
        g[v].push_back({ u, w });
    }
    vector<ll> colors(n + 1, -1);
    queue<int> q;
    q.push(1);
    colors[1] = 0;
    while (!q.empty()) {
        int f = q.front();
        q.pop();
        for (auto &v : g[f]) {
            if (colors[v.first] < 0) {
                q.push(v.first);
                if (colors[f]) {
                    if (v.second % 2 == 0)
                        colors[v.first] = 1;
                    else
                        colors[v.first] = 0;
                } else {
                    if (v.second % 2 == 0)
                        colors[v.first] = 0;
                    else
                        colors[v.first] = 1;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << colors[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 8704
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = (1..(N + 1))
        .find(|&i| (i * 108 / 100) == N)
        .map_or(":(".to_string(), |x| x.to_string());
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, l;
    cin >> n >> l;
    vint a(n);
    vint d(n-1);
    int idx = INF;
    rep(i, n) {
        cin >> a[i];
        if (i > 0) {
            d[i-1] = a[i-1] + a[i];
            if (d[i-1] >= l) idx = i-1;
        }
    }
    if (idx == INF) {
        puts("Impossible");
        return 0;
    }
    puts("Possible");
    rep(i, idx) {
        cout << i+1 << endl;
    }
    for (int i = n-2; i > idx; --i) {
        cout << i+1 << endl;
    }
    cout << idx+1 << endl;

    return 0;
}

Measured memory_bytes: 1664
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(void)
{
    long long a, b, c;

    cin >> a >> b >> c;
    if(a + b >= c)
        cout << "No" << endl;
    else
        cout << (4LL * a * b < (long long)(c - a - b) * (c - a - b) ? "Yes" : "No") << endl;

    return 0;
}


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

int main(){
	int w,a,b;
	cin >> w >> a >> b;
	if ((a - w) <= b && b <= (a + w)){
		cout << 0 << endl;
	}else{
		cout << max(a - (b + w), b - (a + w)) << endl;
	}
	return 0;
}

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

#define fs first
#define sc second
#define mp make_pair
#define pb emplace_back
#define sz(s) ((int) s.size ())
#define all(s) s.begin (), s.end ()

using namespace std;

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

const ll linf = (ll) 1e18;

const int pw = 997;
const int N = 19;
const int inf = (int) 1e9;
const int mod = (int) 1e9 + 7;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;

int p[N];

bool g[N][N];

inline void prepare () {

}
inline void solve () {
        int n, m; cin >> n >> m;
        for (int i = 0; i < m; i++) {
                int a, b; cin >> a >> b; --a, --b; g[a][b] = g[b][a] = 1;
        }
        for (int i = 0; i < n; i++) {
                p[i] = i;
        }
        int ans = 0;
        do {
                bool good = 1;
                for (int i = 0; i < n - 1; i++) {
                        if (!g[p[i]][p[i + 1]]) {
                                good = 0;
                                break;
                        }
                }
                ans += good;
        }while (next_permutation (p + 1, p + n));
        cout << ans;
}
int main () {
        #ifdef FSTREAM
                #define name ""
                freopen (name".in", "r", stdin);
                freopen (name".out", "w", stdout);
        #endif // FSTREAM
        int tests = 1;
        prepare ();
	while (tests--) {
                solve ();
        }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(void){
  int l,r,r2=90;
  double x=0,y=0;
  double pi=3.141592653589793;
  for(;;){
    scanf("%d,%d",&l,&r);
    if(!l && !r) break;
    x+=l*cos(r2*pi/180);
    y+=l*sin(r2*pi/180);
    r2-=r;
  }
  printf("%d\n%d\n",(int)x,(int)y);
}


Measured memory_bytes: 1192
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)


import sys
import numpy as np

def solve(N, A, UV):
    G = [[0] * 0 for _ in range(N)]
    for i in range(N-1):
        u, v = UV[i]
        G[u].append(v)
        G[v].append(u)
    L = [A[0]]
    Ans = np.zeros(N, dtype=np.int64)
    stack = [(0, 0, 0, -1, -1)]  # 頂点、状態、見ている子のインデックス、行った行動*2
    while stack:
        v, state, idx_Gv, idx_L, old = stack.pop()
        if state == 0:
            Ans[v] = len(L)
        if state == 2:
            if idx_L == -1:
                del L[-1]
            else:
                L[idx_L] = old
        Gv = G[v]
        if len(Gv) == idx_Gv:
            continue
        u = Gv[idx_Gv]
        G[u].remove(v)
        Au = A[u]
        if Au > L[-1]:
            L.append(Au)
            stack.append((v, 2, idx_Gv + 1, -1, -1))
            stack.append((u, 0, 0, -1, -1))
            continue
        else:
            idx_L = np.searchsorted(L, Au)
            old = L[idx_L]
            L[idx_L] = Au
            stack.append((v, 2, idx_Gv + 1, idx_L, old))
            stack.append((u, 0, 0, -1, -1))
            continue
    return Ans

numba_compile([
    [solve, "i8[:](i8,i8[:],i8[:,:])"]
])

def main():
    input = sys.stdin.buffer.readline
    N = int(input())
    A = np.array(input().split(), dtype=np.int64)
    UV = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N-1, 2) - 1
    Ans = solve(N, A, UV)
    print("\n".join(map(str, Ans.tolist())))

main()


Measured memory_bytes: 93608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
ll n, m;
ll a[N], sum[N];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	ll l = 0, r = 2e5 + 1;
	m = 1LL * n * n - m + 1;
	while (l + 1 < r) {
		ll mid = (l + r) >> 1;
		ll sum = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] >= mid)
				break;
			sum += upper_bound(a + 1, a + 1 + n, mid - a[i]) - a - 1;
		}
		if (sum >= m)
			r = mid;
		else
			l = mid;
	}
	for (int i = 1; i <= n; i++) {
		sum[i] = sum[i - 1] + a[i];
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += a[i] * n + sum[n];
	}
	ll res = r, p = 0;
	for (int i = 1; i <= n; i++) {
		ll l = 0, r = n + 1;
		while (l + 1 < r) {
			ll mid = (l + r) >> 1;
			if (a[mid] < res - a[i])
				l = mid;
			else
				r = mid;
		}
		ans -= l * a[i] + sum[l];
		p += l;
	}
	cout << ans - (m - 1 - p) * res;
	return 0;
}

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

int main() {
  int n;
  bool b = 0;
  cin >> n;
  rep(i, n){
    char a;
    cin >> a;
    if(a == 'Y') b = 1;
  }
  if(b) cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  string s;
  cin >> s;
  int n=s.size();
  
  int bl = 0;
  int wh = 0;
  rep(i,n){
    if(i%2==0){
      if(s[i]=='1')bl++;
      else wh++;
    }
    if(i%2==1){
      if(s[i]=='0')bl++;
      else wh++;
    } 
  }
  
  cout << min(bl,wh) << endl;
  
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      int m=sc.nextInt();
      if(m==100)m=101;
      System.out.println((m==0)?0:(n==0)?m:(n==1)?m+"00":m+"0000");
    }
}


Measured memory_bytes: 21844
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, M = in.nextInt
  case class Cake(x: Long, y: Long, z: Long)
  val cakes = Array.fill(N)(Cake(in.nextLong, in.nextLong, in.nextLong))

  def calc(f: Cake => Long): Long = cakes.map(f).sorted.reverse.take(M).sum

  println(
    calc(c =>  c.x + c.y + c.z) max
    calc(c =>  c.x + c.y - c.z) max
    calc(c =>  c.x - c.y + c.z) max
    calc(c =>  c.x - c.y - c.z) max
    calc(c => -c.x + c.y + c.z) max
    calc(c => -c.x + c.y - c.z) max
    calc(c => -c.x - c.y + c.z) max
    calc(c => -c.x - c.y - c.z)
  )
}

Measured memory_bytes: 57908
N = int(input())
H = list(map(int, input().split()))

tmp = 0
ans = 0
for i in range(N-1):
    if H[i+1] <= H[i]:
        tmp += 1
    else:
        if tmp > ans:
            ans = tmp
        tmp = 0
        
print(max(tmp, ans))        

Measured memory_bytes: 14224
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main{
    static int[][] field;
    static int w;
    static int h;

    public static void dfs(int y, int x) {
        field[y][x] = 0;
        for (int i = -1; i < 2; i++) {
            for (int j = -1; j < 2; j++) {
                int nh = y + i;
                int nw = x + j;
                if(nh < 0 || nh >= h || nw < 0 || nw >= w) continue;
                if(field[nh][nw] == 0) continue;
                dfs(nh, nw);
            }
        }
    }

	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            w = sc.nextInt();
            h = sc.nextInt();
            if(w == 0&&h == 0) break;
            field = new int[h][w];

            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    field[i][j] = sc.nextInt();
                }
            }

            int ans = 0;

            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(field[i][j] == 1){
                        dfs(i, j);
                        ans++;
                    }
                }
            }

            System.out.println(ans);
    
        }
        
        sc.close();
    }

    
}



Measured memory_bytes: 46032