akhauriyash/Code-Regression huggingface dataset:
op = ['+', '-']
s = input()

for i in op:
    for j in op:
        for k in op:
            if eval(s[0]+i+s[1]+j+s[2]+k+s[3]) == 7:
                print(s[0]+i+s[1]+j+s[2]+k+s[3]+'=7')
                exit()

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

int main(){
  int n;
  ll v, coin[4][1010];
  cin >> n >> v;
  for(int i=0; i<4; i++){
      for(int j=0; j<n; j++){
          cin >> coin[i][j];
      }
  }
  vector<ll> coin1, coin2;
  for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
          coin1.push_back(coin[0][i]+coin[1][j]);
          coin2.push_back(coin[2][i]+coin[3][j]);
      }
  }
  sort(coin1.begin(), coin1.end());
  sort(coin2.begin(), coin2.end());
  vector<ll>::iterator it;
  ll ans=0;
  for(it=coin1.begin(); it!=coin1.end(); it++){//binary searchでv-(*it)となる値をcoin2から探す
      ans+=upper_bound(coin2.begin(), coin2.end(), v-(*it))-lower_bound(coin2.begin(), coin2.end(), v-(*it));
  }
  cout << ans << "\n";
  
}


Measured memory_bytes: 18772
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <complex>
#include <vector>
using namespace std;

typedef complex<double> P;

struct Circle{
  double r;
  P c;
  Circle(double r=0.0, P c = P(0,0)):r(r),c(c){}
  bool operator < (const Circle &c) const {
    return r < c.r;
  }
};

const double EPS = 1e-8;

int n;
double hi;
Circle v[11];

bool equal(double a, double b){ return fabs(a-b) < EPS;}

double dot(P a, P b){ return real(conj(a)*b);}
double cross(P a, P b){ return imag(conj(a)*b);}

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersectCP(P p, Circle c){
  return abs(c.c-p) < c.r || equal(abs(c.c-p),c.r);
}

vector<P> intersectCC(Circle C1, Circle C2){
  vector<P> res;
  double r1 = C1.r, r2 = C2.r, d;
  P p1 = C1.c, p2 = C2.c;
  d = abs(p1-p2);
  if(d < EPS && abs(r1-r2) < EPS) return res;
  if(r1 + r2 < d - EPS || d + EPS < abs(r1-r2)) return res;

  double a = (r1*r1 - r2*r2 + d*d) / (2*d);
  double h = sqrt(max(r1*r1 - a*a, 0.0));
  P tmp1 = p1 + a / d * (p2-p1);
  P tmp2 = h / d * (p2-p1);

  if(abs(tmp2) < EPS) res.push_back(tmp1);
  else{
    res.push_back(P(real(tmp1) - imag(tmp2), imag(tmp1) + real(tmp2)));
    res.push_back(P(real(tmp1) + imag(tmp2), imag(tmp1) - real(tmp2)));
  }
  return res;
}

bool func(vector<Circle> w){
  bool f = false;
  int ws = w.size();
  if(ws == 1) return true;

  //内側に円があれば、交わっていなくてもtrue
  f = false;
  for(int i=1;i<ws;i++) {
    if(abs(w[i].c-w[0].c) > w[i].r-w[0].r && !equal(abs(w[i].c-w[0].c),w[i].r-w[0].r)){
      f = true;
      break;
    }
  }
  if(!f)  return true;


  //円の交点を求め、１つでも全ての円の内側・境界に存在するならtrue
  vector<P> p;
  for(int i=0;i<ws;i++){
    for(int j=i+1;j<ws;j++){
      vector<P> aa = intersectCC(w[i],w[j]);
      for(int k=0;k<aa.size();k++) p.push_back(aa[k]);
    }
  }
  for(int i=0;i<p.size();i++){
    int j;
    for(j=0;j<ws;j++){
      if(!isIntersectCP(p[i],w[j])) break;
    }
    if(j == ws) return true;
  }
  return false;
}

bool check(double h){
  if(n == 1) return h < v[0].r;
  vector<Circle> w;

  for(int i=0;i<n;i++) w.push_back(Circle(sqrt(v[i].r*v[i].r - h*h), v[i].c));
  sort(w.begin(),w.end());
  return func(w);
}

void solve(){
  double c,lo=0.0;
  for(int i=0;i<100;i++){
    c = (lo + hi) / 2.0;
    if(check(c)) lo = c;
    else hi = c;
  }
  printf("%.7f\n",hi);
}

int main(){
  while(cin >> n && n){
    hi = 400.0;
    for(int i=0;i<n;i++){
      double x,y;
      cin >> x >> y >> v[i].r;
      v[i].c = P(x,y);
      hi = min(hi, v[i].r);
    }
    solve();
  }

}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,a,k,i,j;
	ld arr[200005],x,max;
	cout<<fixed<<setprecision(15);
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>a;
		arr[i]=(a+1);
		arr[i]/=2;
	}
	x=0;
	for(i=0;i<k;i++)
	{
		x+=arr[i];
	}
	max=x;
	for(i=k;i<n;i++)
	{
		x+=arr[i];
		x-=arr[i-k];
		if(x>max)
		{
			max=x;
		}
	}
	cout<<max;
	return 0;
}

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

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

    int res = N;

    //Nを6^p+aで作る部分と9^q+bで作る部分に分解し、その全通りを試す
    for(int i=0; i<=N; i++) {
        int temp = 0;
        int t = i;

        //6^pを6回引き出すことは6^(p+1)を1回引き出すことに等しいため、作りたい数を
        //6で割り、その余りを結果の候補に足し込むことを繰り返せばよい。
        //例えば45をつくるとき、1回目のループで45=6*7+3よりtemp=3, t=7となり、
        //2回目のループで7=6*1+1よりtemp=3+1=4, t=1となる。最後のループで
        //残った1がtempに足し込まれ、結果として45=(6^2)+6+3という計算に正しく
        //従っていることがわかる。
        while(t>0) {
            temp += t%6;
            t /= 6;
        }

        //9^q+bで作る部分も同様
        t = N-i;
        while(t>0) {
            temp += t%9;
            t /= 9;
        }

        if(res > temp) res = temp;
    }

    cout << res << endl;
    return 0;
}

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

int main()
{
    vector<char> vowels{'a', 'i', 'u', 'e', 'o'};
    char c;
    cin >> c;

    for (auto v : vowels)
    {
        if (v == c)
        {
            cout << "vowel";
            return 0;
        }
    }
    cout << "consonant";
}

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

int main(){
string S="ABCD";
  for(int i=0;i<S.size();i++){
    cin>>S.at(i);
  }
  

  
  if(10*(S.at(0)-'0')+(S.at(1)-'0')>0&&10*(S.at(0)-'0')+(S.at(1)-'0')<=12){
    if(10*(S.at(2)-'0')+S.at(3)-'0'>0&&10*(S.at(2)-'0')+(S.at(3)-'0')<=12){
      cout<<"AMBIGUOUS"<<endl;
    }

    else{
      cout<<"MMYY"<<endl;
    }
    }
    else if(10*(S.at(0)-'0')+(S.at(1)-'0')==0||10*(S.at(0)-'0')+(S.at(1)-'0')>12){
       if(10*(S.at(2)-'0')+(S.at(3)-'0')>0&&10*(S.at(2)-'0')+(S.at(3)-'0')<=12){
        cout<<"YYMM"<<endl;
      }
      else{
        cout<<"NA"<<endl;
      }
    }
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define loop(n) for (ll i = 0; i < n; i++)
#define loopy(n) for (ll j = 0; j < n; j++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define oo 1e18
#define fr first
#define se second
using namespace std;
const int N = 5e5 + 10;
const int M = 1e7 + 10;
const ll mod = 1e9 + 7;
int a[N] ; 
int dp[N] ; 
int main()
{
    int n ; cin >> n ; 
    for( int i = 0 ; i < n ; i ++ ){
        cin >> a[i] ; 
    }
    dp[n-1] =  0 ;
    for( int i = n - 2 ; i >= 0 ; i -- ) {
        dp[i] = max ( 0 , ( a[i + 1] <= a[i] ) * ( 1 + dp[i+1] ) ) ; 
    }
    int mx = -1 ; 
    for( int i = 0 ; i < n ; i ++ ){
        mx = max ( mx , dp[i] ) ; 
    }   
    cout<<mx<<endl ;
    return 0;
}


Measured memory_bytes: 1024
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(long long i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	int n;	cin >> n;
	map <string,int> m;
	Rep(i,0,n){
		string x;	cin >> x;
		if(!m[x]){
			m[x] = 0;
		}
		m[x]++;
	}
	cout << "AC" << " x " << m["AC"] << endl;
	cout << "WA" << " x " << m["WA"] << endl;
	cout << "TLE" << " x " << m["TLE"] << endl;
	cout << "RE" << " x " << m["RE"] << endl;
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	//int t;	cin >> t;
	while(t--) Solve();
	return 0;
}


Measured memory_bytes: 3656
import sys
N,M=map(int,input().split())
edge=[]
for i in range(M):
    a,b,c=map(int,input().split())
    edge.append([a-1,b-1,-c])
inf=10**30
dist=[inf]*N
dist[0]=0
for i in range(N+1):
    for x,y,z in edge:
        if dist[y]<= dist[x]+z:
            continue
        dist[y]=dist[x]+z
        if i==N and y==N-1:
            print('inf')
            sys.exit()
print(-dist[N-1])

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

using namespace std;

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

    int n , q;
    cin >> n >> q;

    vector<pair<int , int> > starts , ends;

    int s , e , x;
    for (int i = 0 ;i < n ;i++) {
        cin >> s >> e >> x;
        if (x < s) {
            starts.push_back({s - x, x});
            ends.push_back({e - x , x});
        } else if (x <= e) {
            starts.push_back({0 , x});
            ends.push_back({e - x , x});
        }
    }

    sort(starts.begin() , starts.end());
    sort(ends.begin() , ends.end());

    vector<pair<int , int> > v(q);
    for (int i = 0 ;i < q ;i++) {
        cin >> v[i].first;
        v[i].second = i;
    }

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

    vector<int> ans(q);

    int k = 0 , j = 0;
    multiset<int> ms;
    for (int i = 0 ;i < v.size() ;i++) {
        while (k < starts.size() && starts[k].first <= v[i].first)
            ms.insert(starts[k].second) , k++;

        while (j < ends.size() && ends[j].first <= v[i].first)
            ms.erase(ms.find(ends[j].second)) , j++;

        if (ms.size())
            ans[v[i].second] = *ms.begin();
        else
            ans[v[i].second] = -1;
    }


    for (auto x : ans)
        cout << x << '\n';
}


Measured memory_bytes: 17124
#include <stdio.h>

int main(void)
{
  int i, x = 0, y = 0;
  int t[4];

  for (i = 0; i < 4; i++)
    {
      scanf("%d", &t[i]);

      y = y + t[i];
    }

  x = y / 60;
  y = y % 60;
  
  printf("%d\n%d\n", x, y);

  return 0;
}

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


int main()
{
    long long int a,b,n;

    cin >> n>>a >>b;

    if(n<2){
        if(n==0)
            cout << "0";
        else {
            if(a==b)
                cout << "1";
            else
                cout << "0";
        }

    }
    else{
        if(a>b)
            cout << "0" ;
        else
            cout << ( (n-2)*b - (n-2)*a +1  ) ;
    }


    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] l = new int[n];
        for (int i = 0 ; i < n ; i++) {
            l[i] = sc.nextInt();
        }
        Arrays.sort(l);
        int count = 0;
        for (int i = 0 ; i < n ; i++) {
            for (int j = i + 1 ; j < n ; j++) {
                for (int k = j + 1 ; k < n ; k++) {
                    if (l[j] < l[i] + l[k] && l[k] < l[i] + l[j] ) count++;
                }
             }
        }
        System.out.println(count);
    }

}

Measured memory_bytes: 26868
def sub():
    N, K = [int(e) for e in input().split()]
    As = [int(e) for e in input().split()]

    bK = "{:b}".format(K)
    # print(bK)
    size_K = len(bK)
    fmt = "{:0" + str(size_K) + "b}"
    bAs = [fmt.format(a) for a in As]
    bAs = [a[-size_K:] for a in bAs]
    # print(bAs)
    buf = []
    d = float(N) / 2.0
    flagFree = False
    for i in range(size_K):
        k = bK[i]
        if k == "0" and flagFree is False:
            buf.append("0")
            continue
        cc = [int(a[i]) for a in bAs]
        t = sum(cc)
        if t > d:
            buf.append("0")
            if k == "1":
                flagFree = True
        else:
            buf.append("1")
    xOpt = "".join(buf)
    xOpt = int(xOpt,2)

    ans = [xOpt ^ a for a in As]
    print(sum(ans))


if __name__ == "__main__":
    sub()





Measured memory_bytes: 122648
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x, vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1, s) + f(x - 2, s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m - 1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main() {
	ll x;
	ll ans = 0;
	cin >> x;
	ans = 2 * (x / 11);
	x %= 11;
	if (x > 6)ans += 2;
	else if(x > 0)ans++;
	cout << ans << endl;
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    long long fact=1;
    for(int i=2; i<=n; i++) fact*=i;
    cout<<fact<<'\n';
    return 0;
}

Measured memory_bytes: 3216
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();

        for(int i=1;i<10;i++){
            for(int j=1;j<10;j++){
                if(i*j==n){
                    System.out.println("Yes");
                    return;
                }
            }
        }

        System.out.println("No");

        scn.close();

    }


}


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

ll p(ll a , ll b)
{
    ll ans = 1 ;
    while(b)
    {
        if(b%2)
        {
            ans *= a ;
        }
        a *= a ;
        b /= 2 ;
    }
    return ans ;
}

int main()
{
    ll a , b , c ;
    cin >> a >> b >> c ;
    a += (b-1) ;
    a /= b ;
    cout << a*c << endl ;
}


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

int main(){
  string str;
  cin >> str;
  int len = 0, first, end;
  for(int i = 0; i < str.size(); i++){
    if(str.at(i) == 'A'){
      first = i;
      break;
    }
  }
  for(int i = str.size()-1; i > 0; i--){
    if(str.at(i) == 'Z'){
      end = i;
      break;
    }
  }
  cout << end - first + 1 << endl;
}
    

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
  speed;
  ll n,t=0;
  
  cin>>n;
  ll a[n];
  
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    t^=a[i];
  }
  
  for(int i=0;i<n;i++)
    cout<<(t^a[i])<<" ";
  
  return 0;
}
  

Measured memory_bytes: 5152
n,m = (int(i) for i in input().split())
ab = [[int(i) for i in input().split()] for i in range(n)]
cd = [[int(i) for i in input().split()] for i in range(m)]

for x1 in ab:
    min_dist = 10**10
    min_idx = 0
    for idx,x2 in enumerate(cd):
        dist = abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])
        if dist < min_dist:
            min_dist = dist
            min_idx = idx
    
    print(min_idx+1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S, S1, S2, S3, S4, S5, S6, S7, S8;
    cin >> S;
    int N = S.size();
    rep(i, 0, ((N - 1) / 2))
    {
        S1 += S.at(i);
    }
    rep(i, (N + 3) / 2 - 1, N)
    {
        S2 += S.at(i);
    }
    rep(i, 0, N / 2)
    {
        S3 += S.at(i);
        S4 += S.at(N - i - 1);
    }
    if (S3 != S4)
    {
        cout << "No" << endl;
        return 0;
    }
    int N1 = S1.size();
    rep(i, 0, N1)
    {
        S5 += S1.at(i);
        S6 += S1.at(N1 - i - 1);
    }
    if (S5 != S6)
    {
        cout << "No" << endl;
        return 0;
    }
    int N2 = S2.size();
    rep(i, 0, N2)
    {
        S7 += S2.at(i);
        S8 += S2.at(N2 - i - 1);
    }
    if (S7 != S8)
    {
        cout << "No" << endl;
        return 0;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n;
  int a, b, c, d;
  int cnt;

  while (scanf("%d", &n) != EOF){
    
    cnt = 0;
    for (a = 0; a < 10; a++){
      for (b = 0; b < 10; b++){
	for (c = 0; c < 10; c++){
	  for (d = 0; d < 10; d++){
	    if (a + b + c + d == n){
	      cnt ++;
	      break;
	    }
	  }
	}
      }
    }
 
    printf("%d\n", cnt);
  }
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main()
{
  int n;

  scanf("%d", &n);

  if (n >= 65 && n <= 90) {
    printf("1\n");
  } else if (n >= 97 && n <= 122) {
    printf("2\n");
  } else {
    printf("0\n");
  }

  return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  int n; cin >> n;
  auto a = make_v(3 * n, 0LL);

  priority_queue<ll, vector<ll>, greater<ll>> p;
  priority_queue<ll> q;

  ll psum = 0, qsum = 0;
  REP(i, 3 * n){
    cin >> a[i];
    if(i < n){
      p.push(a[i]);
      psum += a[i];
    }
    if(2 * n <= i && i < 3 * n){
      q.push(a[i]);
      qsum += a[i];
    }
  }

  vector<ll> pm(n+1), qm(n+1);
  pm[0] = psum; qm[0] = qsum;

  REP(i, n){
    p.push(a[n + i]); psum += a[n + i];
    psum -= p.top(); p.pop();
    pm[i + 1] = psum;

    q.push(a[2*n - 1 - i]); qsum += a[2* n - 1 - i];
    qsum -= q.top(); q.pop();
    qm[i + 1] = qsum;
  }

  ll ans = numeric_limits<ll>::min();
  FOR(i, 0, n+1){
    ll tmp = pm[i] - qm[n - i];
    ans = max(ans, tmp);
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
#define MAXN 100

using namespace std;

int v[MAXN + 1];

int main() {
   // fstream cin("A.in");
   // ofstream cout("A.out");
    int i,n,j;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 1; i <= n; i++)
        cin >> v[i];
    int mn = (1 << 30);
    for(i = -100; i <= 100; i++) {
        int ans = 0;
        for(j = 1; j <= n; j++)
            ans += (i - v[j]) * (i - v[j]);
        if(ans < mn)
            mn = ans;
    }
    cout << mn << endl;
   // cin.close();
   // cout.close();
    return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------
const int INF = 1e9+1000;
ll n, a, b;
ll h[111111];

int main() {
   cin >> n >> a >> b;
   rep (i, n) cin >> h[i];

   int c = a - b;
   int left = 0, right = INF;
   while (left+1<right) {
      ll mid = (left+right)/2;
      ll cnt = 0;
      rep (i, n) {
         ll t = max(h[i] - mid * b, 0LL);
         cnt += (t+c-1) / c;
      }
      if (cnt <= mid) {
         right = mid;
      } else {
         left = mid;
      }
   }
   cout << right << endl;

   return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,k;
    int minh=100000000000;
    cin>>n>>k;
        vector<int> h(n);
    for(int i=0;i<n;++i){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    for(int i=0;i<n-k+1;++i){
        minh=min(minh,h[i+k-1]-h[i]);
    }
    cout<<minh<<endl;
}

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

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
template <class T>
class dice { 
	public:
		dice() {
			id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 2;
			id[RIGHT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
		}
		T& operator[] (FACE f) { return var[id[f]]; }
		const T& operator[] (FACE f) const { return var[id[f]]; }
		bool operator==(const dice<T>& b) const {
			const dice<T> &a = *this;
			return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
				a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
				a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
		}
		void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
		void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
		void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
		vector<dice> all_rolls() {
			vector<dice> ret;
			for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
				for (int i = 0; i < 4; roll_z(), ++i)
					ret.push_back(*this);
			return ret;
		}
		bool equivalent_to(const dice& di) {
			for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
				for (int i = 0; i < 4; roll_z(), ++i)
					if (*this == di) return true;
			return false;
		}
	protected:
		void roll(FACE a, FACE b, FACE c, FACE d) {
			T tmp = id[a];
			id[a] = id[b]; id[b] = id[c];
			id[c] = id[d]; id[d] = tmp;
		}
		T var[6];
		int id[6];
};

template <class T>
class mydice : public dice<T> {
	public:
		mydice(T top, T front, T right, T left, T back, T bottom) {
			this->var[this->id[TOP]] = top;
			this->var[this->id[FRONT]] = front;
			this->var[this->id[RIGHT]] = right;
			this->var[this->id[LEFT]] = left;
			this->var[this->id[BACK]] = back;
			this->var[this->id[BOTTOM]] = bottom;
		}
		void roll_n() { this->roll(TOP, FRONT, BOTTOM, BACK); }
		void roll_e() { this->roll(TOP, LEFT, BOTTOM, RIGHT); }
		void roll_w() { this->roll(TOP, RIGHT, BOTTOM, LEFT); }
		void roll_s() { this->roll(TOP, BACK, BOTTOM, FRONT); }
};

main () {
	int q, n[6];
	mydice<int>* d[100];
	cin >> q;
	for (int j=0; j<q; j++) {
		for (int i=0; i<6; i++) cin >> n[i];
		d[j] = new mydice<int>(n[0], n[1], n[2], n[3], n[4], n[5]);
	}
	for (int i=0; i<q-1; i++) {
		for (int j=i+1; j<q; j++) {
			if (d[i]->equivalent_to(*d[j])) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

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

namespace ITP1_4_D
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int min = nums[0];
            int max = nums[0];
            long sum = nums[0];
            foreach (var n in nums.Skip(1))
            {
                min = Math.Min(n, min);
                max = Math.Max(n, max);
                sum += n;
            }
            Console.WriteLine("{0} {1} {2}", min, max, sum);
        }
    }
}

Measured memory_bytes: 10488
require 'complex'
require 'prime'
n, m = gets.split.map(&:to_i)
ans = 1
to = [m/2, 100000].max 
(1..Math.sqrt(m)).each do |v|
    if m % v == 0 then
        u = m / v
        ans = v if n <= m / v && ans < v
        ans = u if n <= m / u && ans < u
    end
end
puts ans


Measured memory_bytes: 3964
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M;
ll p[100010];
vector<ll> verts[100010];
bool checked[100010];
vector<ll> places;
set<ll> nums;
void Serch(ll n){
    places.push_back(n);
    nums.insert(p[n]);
    checked[n]=true;
    for(auto v:verts[n]){
        if(!checked[v]){
            Serch(v);
        }
    }
}

int main(){
    cin>>N>>M;
    for(ll i=0;i<N;i++){
        cin>>p[i];
        p[i]--;
    }
    for(ll i=0;i<M;i++){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        verts[x].push_back(y);
        verts[y].push_back(x);
    }
    ll ans=0;
    for(ll i=0;i<N;i++){
        if(!checked[i]){
            Serch(i);
            for(auto pl:places){
                if(nums.find(pl)!=nums.end()){
                    ans++;
                }
            }
            places.clear();
            nums.clear();
        }
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 15092
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b; cin >> a >> b;
    if(a.size() > b.size()) cout << "GREATER";
    if(a.size() < b.size()) cout << "LESS";
    if(a.size() == b.size()){
        if(a > b) cout << "GREATER";
        if(a < b) cout << "LESS";
        if(a == b) cout << "EQUAL";
    }
    cout << endl;
    return 0;
}




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

using namespace std;

const int Nmax = 305, Mod = 998244353;

int dp[Nmax][Nmax][Nmax];
string s;
int k;
vector<int> all;

void add_to(int &x, int y)
{
    x += y;
    if(x >= Mod) x-=Mod;
}

int main()
{
    //freopen("input", "r", stdin);
    cin.sync_with_stdio(false);
    cin.tie(0);

    cin >> s >> k;

    int nr = 0, ones = 0;
    for(auto it : s)
        if(it == '0') all.push_back(nr), nr = 0;
            else ++nr, ++ones;

    all.push_back(nr);
    k = min(k, ones);

    dp[all.size()][0][0] = 1;

    int sum = 0;
    int i, j, cnt, p;

    for(i = all.size() - 1; i>=0; --i)
    {
        sum += all[i];

        for(j=0; j<=sum; ++j)
            for(cnt=0; cnt<=j; ++cnt)
                for(p=0; p<=k; ++p)
                    add_to(dp[i][j][p], dp[i+1][j-cnt][p -max(0, cnt - all[i])]);
    }

    int ans = 0;
    for(i=0; i<=k; ++i)
        add_to(ans, dp[0][ones][i]);
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 30556
#include<iostream>
using namespace std;
static const int SIZE =100;

int main(){
  int n, m, a[SIZE][SIZE], b[SIZE];
  cin >> n >> m;

  for(int i=0; i<n; i++)
    for(int j=0; j<m; j++)
      cin >> a[i][j];

  for(int i=0; i<m; i++)
    cin >> b[i];

  for(int i=0; i<n; i++){
    int tmp=0;
    for(int j=0; j<m; j++)
      tmp += a[i][j] * b[j];
    cout << tmp << endl;
  }
  return 0;
}


Measured memory_bytes: 3144
//#include <fstream>

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int NMAX = 200005;
const int KMAX = 3005;
const int MOD = 1000000007;

struct point
{
	int x, y;
	point()
	{
		this->x = this->y = 0;
	}
	point(const int &x, const int &y)
	{
		this->x = x;
		this->y = y;
	}
	inline bool operator<(const point &other)const
	{
		if (this->x == other.x)
			return this->y < other.y;
		return this->x < other.x;
	}
};

int n, m, k;
point v[KMAX];
int fact[NMAX], invfact[NMAX], d[NMAX];

int lgput(int base, int exp)
{
	int res = 1;
	while (exp > 0)
	{
		if (exp & 1)
			res = (1LL * res * base) % MOD;
		base = (1LL * base * base) % MOD;
		exp >>= 1;
	}
	return res;
}

inline int invmod(int &x)
{
	return lgput(x, MOD - 2);
}

inline int comb(int n, int k)
{
	int ret = (1LL * fact[n] * invfact[k]) % MOD;
	ret = (1LL * ret * invfact[n - k]) % MOD;
	return ret;
}

inline int calc(int x1, int y1, int x2, int y2)
{
	int p = abs(x2 - x1);
	int q = abs(y2 - y1);
	return comb(p + q, p);
}

int main()
{
	//ifstream cin("test.in");
	//ofstream cout("test.out");
	cin >> n >> m >> k;
	fact[0] = 1;
	invfact[0] = invmod(fact[0]);
	for (int i = 1;i <= n + m;++i)
	{
		fact[i] = (1LL * fact[i - 1] * i) % MOD;
		invfact[i] = invmod(fact[i]);
	}
	for (int i = 1;i <= k;++i)
	{
		int x, y;
		cin >> x >> y;
		v[i] = point(x, y);
	}
	sort(v + 1, v + k + 1);
	v[++k] = point(n, m);
	for (int i = 1;i <= k;++i)
	{
		d[i] = calc(1, 1, v[i].x, v[i].y);
		for (int j = 1;j < i;++j)
		{
			if (v[j].x <= v[i].x && v[j].y <= v[i].y)
			{
				int diff = (1LL * d[j] * calc(v[j].x, v[j].y, v[i].x, v[i].y)) % MOD;
				d[i] = (d[i] - diff + MOD) % MOD;
			}
		}
	}
	cout << d[k] << "\n";
	return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int T,A,X,B,Y,C,D;
vector<pair<int,int> > s;
int _gcd(int a,int b){
	if(b==0)return a;
	return _gcd(b,a%b);
}
void init(){
	int g=_gcd(A,B);
	A/=g,B/=g,C/=_gcd(g,C);
	g=_gcd(A,C),A/=g,C/=g,Y/=g;
	g=_gcd(B,C),B/=g,C/=g,X/=g;
}
void exgcd(int a,int b,int &x,int &y){
	if(b==0){
		x=1,y=0;
		return;
	}
	exgcd(b,a%b,x,y);
	int t=x;
	x=y;
	y=t-a/b*y;
}
inline int Inv(int a,int mod){
	int x,y;
	exgcd(a,mod,x,y);
	return (x+mod)%mod;
}
inline int Get(int x){
	return !x?C:(C-1LL*x*D%C)%C;
}
void Get_seg(){
	D=1LL*A*Inv(B,C)%C;
	s.clear();
	int W=C,H=D,now=0,invD=Inv(D,C);
	while("MAK AK IOI!"){
		s.emplace_back(W/H,(int)(1LL*now*invD%C));
		now+=W/H*H;
		if(!(W%=H))break;
		if(!(H%=W))H=W;
	}
	s.emplace_back(0,C);
}
int main(){
	T=read();
	while(T--){
		A=read(),X=read(),B=read(),Y=read(),C=read();
		init();
		if(C==1){
			printf("%d\n",X+Y);
			continue;
		}
		Get_seg();
		ll mx=0;
		for(int i=0;i<(int)s.size()-1;++i){
			int lx=s[i].second,rx=s[i+1].second;
			int ly=Get(lx),ry=Get(rx);
			int dx=(rx-lx)/s[i].first,dy=(ly-ry)/s[i].first;
			
			auto check=[=](ll k) -> bool{
				if(X-k*lx<0||Y-k*ry<0)return false;
				int a=(X-k*lx)/dx,b=(Y-k*ry)/dy;
				return a+b>=k*s[i].first;
			};
			
			ll l=0,r=X+Y+1,ans=0;
			while(l<r){
				ll mid=(l+r)>>1;
				if(check(mid)){
					ans=mid,l=mid+1;
				}
				else{
					r=mid;
				}
			}
			mx=max(mx,ans);
		}
		printf("%lld\n",mx);
	}
	return 0;
}



Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

long long m = 1e9+7, mod = 1e9+7;
//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

//約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


int main() {
  string str;
  cin >> str;
  map<string,int> m;
  m["SUN"]=7;
  m["MON"]=6;
  m["TUE"]=5;
  m["WED"]=4;
  m["THU"]=3;
  m["FRI"]=2;
  m["SAT"]=1;
  cout << m[str] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll sum[n+1];sum[0]=0;
    rep(i,1,n){
        sum[i]=sum[i-1]+a[i-1];
    }
    ll ans=inf;
    rep(i,2,n-2){
        
        ll l=1;
        ll r=i;
        vector<l_l> v[2];
        while(r-l>1){
            ll mid=(r+l)/2;
            if(2*sum[mid]<sum[i]){
                l=mid;
            }else{
                r=mid;
            }
        }
        v[0].pb(l_l(min(sum[l],sum[i]-sum[l]),max(sum[l],sum[i]-sum[l])));
        l++;
        if(l!=i){
            v[0].pb(l_l(min(sum[l],sum[i]-sum[l]),max(sum[l],sum[i]-sum[l])));
        }
        
        l=i+1;
        r=n;
        while(r-l>1){
            ll mid=(r+l)/2;
            if(2*(sum[mid]-sum[i])<sum[n]-sum[i]){
                l=mid;
            }else{
                r=mid;
            }
        }
        v[1].pb(l_l(min(sum[l]-sum[i],sum[n]-sum[l]),max(sum[l]-sum[i],sum[n]-sum[l])));
        l++;
        if(l!=n){
            v[1].pb(l_l(min(sum[l]-sum[i],sum[n]-sum[l]),max(sum[l]-sum[i],sum[n]-sum[l])));
        }
        
        rep(j,0,(ll)v[0].size()-1){
            rep(k,0,(ll)v[1].size()-1){
                ll mini=min(v[0][j].first,v[1][k].first);
                ll maxi=max(v[0][j].second,v[1][k].second);
                
                ans=min(ans,maxi-mini);
            }
        }
        
    }
    cout<<ans<<endl;
    
    return 0;
}





Measured memory_bytes: 6672
#include <iostream>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n ;
    cin >> n;
    int a[n + 1] , b[n + 1];
    for ( int i = 1 ; i <= n ; i++ ) {
        cin >> a[i];
    }
    int i=1;
    int count = 0;
    while ( i != 2 ) {
    	int p = a[i];
    	b[i]=p;
    	i = p;
    	count ++;
    	if (count>n){
    		cout << -1 << endl;
    		return 0;	
    	} 
    }
    cout << count;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 201

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

bool is_prime(int x){

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

  return true;
}

bool calc(){
  int a,d,n;

  scanf("%d%d%d",&a,&d,&n);

  if(a==0) return false;
  
  for(int i=0;;i++){
    n -= is_prime(a+d*i);

    if(n==0){
      printf("%d\n",a+d*i);
      return true;
    }
  }

  return true;
}

int main(){
  int n;
  
  while(calc());
  
  return 0;
}

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

using namespace std;

using ll = std::int64_t;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
std::vector<std::vector<ll>> p;

struct TreeDP {
  using dp_t = std::vector<std::map<ll, ll>>;
  const std::vector<std::vector<ll>> &tree;
  const std::size_t sz;
  dp_t dp;

  TreeDP(const std::vector<std::vector<ll>> &tree) : tree(tree), sz(tree.size()), dp(sz) {}

  ll dfs1(ll cur, ll pre) {
    ll ret = 0;
    for (ll nxt : tree[cur])
      if (nxt != pre) {
        ll res = dfs1(nxt, cur);
        dp[cur][nxt] = res;
        ret = std::max(ret, res);
      }
    return ret + 1;
  }

  void dfs2(ll cur, ll pre, ll plen) {
    if (0 <= plen) dp[cur][pre] = plen;
    std::vector<std::pair<ll, ll>> lenv;
    for (ll nxt : tree[cur]) lenv.emplace_back(dp[cur][nxt], nxt);

    std::sort(lenv.rbegin(), lenv.rend());
    for (ll nxt : tree[cur])
      if (nxt != pre) {
        ll a, b;
        std::tie(a, b) = lenv[0];
        if (b == nxt) {
          if (2 <= lenv.size()) std::tie(a, b) = lenv[1];
          else a = 0;
        }
        dfs2(nxt, cur, a + 1);
      }
  }

  dp_t solve() {
    dfs1(0, -1);
    dfs2(0, -1, -1);
    return dp;
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  p.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }
  TreeDP t(p);
  auto r = t.solve();
  int diameter = 0, ng = 0;
  for (int i = 0; i < n; i++) {
    vector<int> d;
    for (auto &&j : r[i]) {
      d.push_back(j.second);
    }
    sort(d.rbegin(), d.rend());
    if (d.size() >= 2) {
      diameter = max(diameter, (int) (d[0] + d[1]));
    }
    if (d.size() >= 3) {
      ng = max(ng, (int) min(d[0] * 2 - 1, d[0] + d[2]));
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i <= 2) {
      cout << 1;
    } else {
      if (i <= ng) {
        cout << 0;
      } else {
        cout << 1;
      }
    }
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 59052
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9+7;
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b,c;
  cin>>a>>b>>c;
  if((a!=b&&a==c&&b!=c)||(c!=a&&b!=a&&c==b)||(a!=c&&b!=c&&a==b))
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 256
N = int(input())


# ある自然数未満までのエラトステネスの篩をつくる
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False


def eratosthenes(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0, n) if s[i] and i > 1]


P = [p for p in eratosthenes(55556) if p % 5 == 1]
print(*P[:N], sep=" ")


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

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

    int N;
    string S;

    cin >> N >> S;
    if (N == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    vector<long long> v(26);
    long long ans = 1LL;
    const long long MOD = 1e9 + 7;
    for (int i = 0; i < N; i++)
    {
        v[S[i] - 'a']++;
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] > 0)
        {
            ans *= (v[i] + 1);
            ans %= MOD;
        }
    }

    cout << ans - 1 << endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Set<String> items = new TreeSet<String>();
		final int N = Integer.parseInt(in.next());
		for(int i = 0; i < N; i++) {
			items.add(in.next());
		}
		System.out.println(items.size());
	}
}

Measured memory_bytes: 77788
#include <bits/stdc++.h>
using namespace std;
 
int A[100005],DP[100005];
int main() {
	int n,k;
	cin>>n>>k;
	for(int i=0; i<n; i++) 	cin>>A[i];

	
	DP[0]=0;

	
	for(int i=1;i<=n;i++)
	{
		DP[i]= DP[i-1] + abs(A[i-1]-A[i]);
		
		for(int j=2;j<=k && i-j>=0 ;j++)  DP[i]= min(DP[i-j] + abs(A[i-j]-A[i]), DP[i] );

	}	
	cout<<DP[n-1];
		
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
const long long inf=100000000000005;
long long n,a[maxn],cnt=0,sum=0,mini=inf;
int main()
{
	cin>>n;
	for(long long i=1;i<=n;++i) 
	{
		scanf("%lld",&a[i]);
		sum+=abs(a[i]);
		if(a[i]<0) cnt++;
	}
	if(cnt%2==0)
	{
		cout<<sum; 
		exit(0);
	}
	for(long long i=1;i<=n;++i) mini=min(mini,abs(a[i]));
	cout<<sum-2*mini;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
int C[500],S[500],F[500];
int main(){
    int N,i,j;
    scanf("%d",&N);
    for(i=0;i<N-1;i++)
        scanf("%d%d%d",&C[i],&S[i],&F[i]);
    for(i=0;i<N-1;i++){
        int t=0;
        for(j=i;j<N-1;j++){
            if(t<S[j])t=S[j];
            else{
                t=(t-S[j]+F[j]-1)/F[j]*F[j]+S[j];
            }
            t+=C[j];
        }
        printf("%d\n",t);
    }
    printf("0\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1000005;

int min_factor[MAX+1];
void calc(int n) {
	min_factor[0] = min_factor[1] = -1;
	int i;
	for (i = 2; i*i <= n; i++) {
		if (min_factor[i]) continue;
		min_factor[i] = i;
		for (int j = i*i; j <= n; j += i) {
			if (!min_factor[j]) min_factor[j] = i;
		}
	}
	for (; i <= n; i++) if (!min_factor[i]) min_factor[i] = i;
}

vector<pair<long long, int>> prime_factorization(long long n) {
	vector<pair<long long, int>> v;
	while (n > 1) {
		long long p = min_factor[n];
		int exp = 0;
		while (n % p == 0) {
			n /= p;
			exp++;
		}
		v.emplace_back(p, exp);
	}
	return v;
}

long long gcd(long long a, long long b) {
	if (a < 0) a = -a;
	if (b < 0) b = -b;
	while (a != 0) {
		long long tmp = b % a;
		b = a;
		a = tmp;
	}
	return b;
}

int main() {
	calc(MAX);
	int n;
	cin >> n;
	vector<int> A(n);
	vector<bool> p(MAX, false);
	bool pairwise = true;
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		auto v = prime_factorization(A[i]);
		for (auto e : v) {
			if (p[e.first]) {
				pairwise = false;
			}
			p[e.first] = true;
		}
	}
	if (pairwise) {
		cout << "pairwise coprime" << endl;
		return 0;
	}
	int g = 0;
	for (int i = 0; i < n; i++) {
		g = gcd(g, A[i]);
	}
	if (g == 1) {
		cout << "setwise coprime" << endl;
	}
	else cout << "not coprime" << endl;
	return 0;
}

Measured memory_bytes: 10712
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(i, j) ((i) * w + (j))

void run (void) {
  i32 h, w;
  scanf ("%" SCNi32 "%" SCNi32, &h, &w);
  char *s = ALLOC (h * w + 1, char);
  for (i32 i = 0; i < h; ++i) {
    scanf ("%s", s + i * w);
  }
  i32 *cnt = ALLOC (h * w, i32);
  for (i32 i = 0; i < h; ++i) {
    for (i32 j = 0; j < w; ++j) {
      i32 k = j;
      while (k < w && s[POS(i, k)] == '.') ++k;
      for (i32 l = j; l < k; ++l) {
        cnt[i * w + l] = k - j;
      }
      j = k;
    }
  }
  for (i32 i = 0; i < w; ++i) {
    for (i32 j = 0; j < h; ++j) {
      i32 k = j;
      while (k < h && s[POS(k, i)] == '.') ++k;
      for (i32 l = j; l < k; ++l) {
        cnt[l * w + i] += k - j;
      }
      j = k;
    }
  }
  i32 max = 0;
  for (i32 i = 0; i < h * w; ++i) {
    max = MAX(max, cnt[i] - 1);
  }
  printf ("%" PRIi32 "\n", max);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 19712