akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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


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

typedef pair<int,int> P;

int main(){
	int n;
	while(cin >> n,n){
		int id;
		vector<P> vec;
		for(int ii = 0;ii < n;ii++){
			int add[21] = {},score[21] = {},sum = 0,frame = 0,tou = 1;
			cin >> id;
			for(int i = 0;frame < 10;i++){
				cin >> score[i];
				//cout << score[i] << " " << frame << " " << tou << endl;
				add[i]++;
				if(tou == 1 && score[i] == 10){
					if(frame != 9){
						frame++;
						add[i + 1]++;
						add[i + 2]++;
					}else{
						tou++;
					}
				}else if(tou == 2 && score[i] + score[i - 1] >= 10){
					if(frame == 9) tou = 3;
					else{
						frame++;
						add[i + 1]++;
						tou = 1;
					}
				}else if(tou == 2){
					frame++;
					tou = 1;
				}else if(tou == 3) frame++;
				else tou++;
			}
			for(int i = 0;i < 21;i++){
				sum += score[i] * add[i];
			}
			vec.push_back(P(sum,-id));
		}
		sort(vec.begin(),vec.end(),greater<P>());
		for(int i = 0;i < n;i++){
			cout << -vec[i].second << " " << vec[i].first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0)sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
ll n,ans=0;
vector<ll> a;
int main(){ //srand((unsigned)time(NULL));
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    ll mini = i;
    for (int j = i; j < n; j++) {
      if(a[j] < a[mini]){
        mini = j;
      }
    }
    swap(a[i],a[mini]);
    if(i != mini){
      ans++;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << (i==n-1 ? "":" ");
  }cout << endl;
  cout << ans << endl;
}



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

using namespace std;
const int divisor = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    long long int combination[2019][2019];
    for (int i = 0; i < N + 1; ++i) {
        for (int j = 0; j < i + 1; ++j) {
            if (j == 0 || j == i) {
                combination[i][j] = 1;
            } else {
                combination[i][j] = (combination[i-1][j-1] + combination[i-1][j]) % divisor;
            }
        }
    }

    for (int i = 1; i < K + 1; ++i) {
        cout << (combination[N-K+1][i] * combination[K - 1][i - 1]) % divisor << "\n";
    }
    return 0;
}


Measured memory_bytes: 31616
//Ace
#include <bits/stdc++.h>
using namespace std;
using in = long long;
using str = string;
using pi = pair<in, in>;
using vi = vector<in>;
#define F first
#define S second
#define pb push_back
#define rep(i, k, n) for (in i = k; i < n; ++i)
#define repr(i, k, n) for (in i = k; i >= n; --i)
#define sz(x) (in) x.size()
#define all(x) begin(x), end(x)
const in MOD = 1e9 + 7;
const in N = 1e5 + 1;

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

    in d, t, s;
    cin >> d >> t >> s;
    in dm = t * s;
    if (dm >= d)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

class Main{
	static Scanner s=new Scanner(System.in);
	static int gInt() {return Integer.parseInt(s.next());}
	static long gLong() {return Long.parseLong(s.next());}

	public static void main(String[]$){
		int n=gInt()-1,c[]=new int[n],s[]=new int[n],f[]=new int[n];
		for(int i=0;i<n;++i) {
			c[i]=gInt();
			s[i]=gInt();
			f[i]=gInt();
		}
		for(int i=0;i<n;++i) {
			int sum=0;
			for(int j=i;j<n;++j) {
				sum=Math.max(sum,s[j]);
				sum=(sum+f[j]-1)/f[j]*f[j];
				sum+=c[j];
			}
			System.out.println(sum);
		}
		System.out.println(0);
	}
}

Measured memory_bytes: 25272
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int []d = new int[n];
        for (int i = 0;i<n;++i) d[i] = sc.nextInt();
        final int size = d.length;
        Arrays.sort(d);
        int a = d[size/2 - 1];
        int b = d[size/2];

        System.out.println(b-a);
        sc.close();
    }
}

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

int main() {
	int A, B, C, D;
  	cin >> A >> B >> C >> D;
  
  	int L = A + B, R = C + D;
  
	if (L > R) {
    cout << "Left" << endl;
  } else if (L < R) {
    cout << "Right" << endl;
  } else {
	cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>


struct QQ{
	long long x, y;
};


long long ABS(long long V){
	if(V < 0)
		return -V;
	
	return V;
}

int main(){
	
	//freopen("file", "r", stdin);
	
	int N, M; scanf("%d %d", &N, &M);
	
	QQ A[55];
	QQ C[55];
	
	for(int i = 0; i < N; ++i){
		long long x, y;
		scanf("%lld %lld", &x, &y);
		
		A[i].x = x;
		A[i].y = y;	
	}
	
	for(int i = 0; i < M; ++i){
		long long x, y;
		scanf("%lld %lld", &x, &y);
		
		C[i].x = x;
		C[i].y = y;	
	}
	
	for(int i = 0; i < N; ++i){
		
		long long ans = ABS(A[i].x - C[0].x) + ABS(A[i].y - C[0].y);
		int idx = 0;
		
		for(int j = 0; j < M; ++j){
			if(ABS(A[i].x - C[j].x) + ABS(A[i].y - C[j].y) < ans){
				ans = ABS(A[i].x - C[j].x) + ABS(A[i].y - C[j].y);
				idx = j;
			}
		}
		
		printf("%d\n", idx + 1);
	}
	
	
return 0;	
}


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

using namespace std;
#define ll long long
#define ld long double
#define point complex <ld>
#define x real()
#define y imag()
#define dot(a,b) ( (conj(a)*(b)).real() )
#define cross(a,b) ( (conj(a)*(b)).imag() )
#define vec(a,b) ((b)-(a))
#define eps 1e-8

int dcmp(ld a , ld b) {return fabs(a-b)<=eps ? 0: a<b ? -1 : 1;}

ld calc(point p , point p2)
{
    ld ds =  (p.x-p2.x)*(p.x-p2.x) + (p.y-p2.y)*(p.y-p2.y);
    return sqrt(ds);
}

bool check(point p , point p2 ,point p3)
{
    ld pp2 = calc(p,p2) , p2p3=calc(p2,p3);

    if (dcmp(pp2,p2p3) != 0) return 0;

    ld pp3 = calc(p,p3);

    if (dcmp(pp3 , sqrt(2)*pp2) != 0) return 0;
    point aa = vec(p,p2) , bb = vec(p,p3);
    if (cross(aa,bb) > 0) return 1;

    return 0;

}

bool isSq(point p , point p2 , point p3 , point p4)
{
    vector<point> v;
    v.push_back(p) , v.push_back(p2) , v.push_back(p3) , v.push_back(p4);

    map <ll,ll> mp;
    set <ll> st;
    for (int i=0; i<v.size(); i++)
    {
        for (int j=0; j<v.size(); j++)
        {
            if (i!=j)
            {
                mp[ (v[i].x-v[j].x)*(v[i].x-v[j].x) + (v[i].y-v[j].y)*(v[i].y-v[j].y) ]++;
                st.insert((v[i].x-v[j].x)*(v[i].x-v[j].x) + (v[i].y-v[j].y)*(v[i].y-v[j].y));
            }
        }
        if (mp.size()!=2) return 0;
        mp.clear();
    }
    if (st.size()!=2) return 0;
    set<ll> ::iterator it=st.begin();
    ll tmp=*it;
    it++; ll tmp2=*it;
    if (tmp2 != 2*tmp) return 0;

  //  point pp = vec(p,p2) , pp2 = vec(p,p3);
  //  if (cross(pp,pp2) > 0) return 1;
    return 1;
}

void solve(point p , point p2 , point p3)
{
    for(int i=-400; i<=400; i++)
    {
        for(int j=-400; j<=400; j++)
        {
            point p4(i,j);
            if (isSq(p,p2,p3,p4))
            {
                cout << p3.x << ' ' << p3.y << ' ' << p4.x << " " << p4.y << "\n";
                exit(0);
            }
        }
    }
}

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

    ll xx,yy,x2,y2,x3,y3,x4,y4;
    cin >> xx >> yy >> x2 >> y2;

    point p(xx,yy),p2(x2,y2);

    for(int i=-400; i<=400; i++)
    {
        for(int j=-400; j<=400; j++)
        {
            point p3(i,j);
            if (check(p,p2,p3))
            {
                solve(p,p2,p3);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
using System;
    using System.Text;
    using System.Collections.Generic;
    using static System.Math;
    using System.Linq;
    using static System.Array;

    namespace ConsoleApp2
    {
        class Program
        {


            static void Main(string[] args)
            {
            //var S = Console.ReadLine().ToCharArray();
            //var T = Console.ReadLine().ToCharArray();
            var S = Console.ReadLine();
            var K = long.Parse(Console.ReadLine());

            var ans = '1';
            for (int i = 0; i < S.Length && i <  K; i++)
            {
                if(S[i] != '1')
                {
                    ans = S[i];
                    break;
                }
            }
            
            Console.WriteLine(ans);
           

            
            }
        }
    }


Measured memory_bytes: 11092
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		new Main().exec();
	}

	void exec() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		for (int i = Math.min(a, b); i >= 1; --i) {
			if (a % i == 0 && b % i == 0) {
				--k;
				if (k == 0) {
					System.out.println(i);
					sc.close();
					return;
				}
			}
		}
		sc.close();
	}

}


Measured memory_bytes: 23508
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define Rep(i,a,n) for(int i = a;i<n;i++)
#define ll long long  
const long long MOD = 1000000007LL;
string id(int n){
    string a = "000000";
    int cnt = 5;
    while(n != 0){
        a[cnt] = to_string(n%10)[0];
        n = n/10;
        cnt--;
    }
    return a;
}
int main(){  
    int n,m;
    cin >> n >> m;
    ll p[m],y[m];
    map<int,int> mpp;//i -> p_i 
    map<int,ll> mpy;//i -> y_i
    map<ll,int> mpz;//y_i -> zyuni;
    map<int,vector<ll>> mpk; //p_i -> set<y_i>
    rep(i,m){
        cin >> p[i] >> y[i];
        mpp[i] = p[i];
        mpy[i] = y[i];
        mpk[p[i]].push_back(y[i]);
    }
    rep(i,n){
        sort(mpk[i+1].begin(),mpk[i+1].end());
        rep(j,mpk[i+1].size()){
            mpz[mpk[i+1][j]] = j+1;
        }
    }
    rep(i,m){
        cout << id(mpp[i]) << id(mpz[mpy[i]]) << endl;
    }
}

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

int main() {
  int N,L;
  cin>>N>>L;
  int buff;
  buff=L;
//  cout<<buff<<endl;
  for(int i=1;i<N;i++){
    buff +=(i+L);
   // cout<<buff<<endl;
  } 
  if(L+N-1<0){
    buff-=L+N-1;
  }else if(L<0){
  }else if(L>=0){
    buff-=L;
  }
  cout<<buff<<endl;  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int q(const int *a,const int *b)
{
	return *b-*a;
}

int main(void)
{
	int n,k,l[50],s=0,i;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)scanf("%d",&l[i]);
	qsort(l,n,sizeof(int),q);
	for(i=0;i<k;i++)s+=l[i];
	printf("%d",s);
	return 0;
}

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

int solve();

int main()
{
    printf("%d\n", solve());
    return 0;
}

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

    int k;
    if (s.size() & 1) k = s.size() / 2 + 1;
    else k = s.size() / 2;

    for (; k < s.size(); k++)
    {
        if (s[k] != s[k - 1] || s[s.size() - k] != s[s.size() - k - 1])
            return k;
    }
    return k;
}

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

#define int long long

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,b) FOR(i,0,b)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,b) ROF(i,0,b)

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define MOD(x,m) ((x)%(m)+(m))%(m)

const int maxn = 2e5+10;

long long a[maxn], s[maxn];

signed main() {
	long long m, n, v, p, ans = 0;
	cin >> n >> m >> v >> p;
	F0R(i,n) {
		cin >> a[i];
	}
	sort(a, a+n);
	F0R(i, n) {
		s[i] = (i?s[i-1]:0)+a[i];
	}
	F0R(i,n) {
		long long num = p-1+i;
		if (a[n-p] > a[i]+m) continue;
		if (num >= v-1) {
			if (a[i]+m >= a[n-p]) {
				ans++;
			}
			continue;
		}
		long long tmp = upper_bound(a, a+n, a[i]+m)-a-1;
//		printf("sum = %d*%d-(%d-%d)\n", (min(tmp,n-p)-i), (a[i]+m), s[min(tmp,n-p)], s[i]);
		long long sum = (min(tmp,n-p)-i)*(a[i]+m)-(s[min(tmp,n-p)]-s[i]);
//		printf("%d:%d %d %d\n", i, tmp, sum, m*(v-num-1));
		if (sum >= m*(v-num-1)) ans++;
	}
	cout << ans;
}


Measured memory_bytes: 1792
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>
#include <climits>
using namespace std;



int main()
{
    int n,a;
    cin>>n>>a;
    int ans=n%500;
    if(ans<=a)cout<<"Yes";
    else cout<<"No";
    //system("pause");
    return 0;
}  

Measured memory_bytes: 256
import collections


def main():
    n = int(input())
    al = list(map(int, input().split()))
    al.sort()

    dp = [1]*(10**6+1) 
    for a in al:
        if dp[a] >= 0:
            dp[a] -= 1
            for i in range(2,10**6//a + 1):
                dp[a*i] -= 2
    
    ans = 0
    for a in al:
        if dp[a] >= 0: ans+=1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 97188
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c>> d;
  int turn1,turn2;
  turn1=a/d;
  if (a%d!=0) turn1+=1;
  turn2=c/b;
  if(c%b!=0) turn2 +=1;
  if(turn1>=turn2)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible" << "\n";
	else
		cout << "Impossible" << "\n";
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include<iomanip>
#include<tuple>
#include<cmath>
using namespace std;
typedef long long unsigned int ll;

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

int main() {
    int n;
    cin>>n;
    //vector<int>v;
    string ans="";
    while(n!=0){
        if(n%2!=0){
            n--;
            ans="1"+ans;
            //.push_back(1);
        }
        else {
            ans="0"+ans;
        }
        //v.push_back(0);
        n/=(-2);
    
    }
   /*for(int i=v.size()-1;i>=0;i--){
       printf("%d",v[i]);
   }
   printf("\n");*/
   if (ans=="")ans="0";
   cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define ll long long

const ll mod = 1e9+7;

int main(){
	ll r;
	cin >> r;
	if (r<1200) cout << "ABC" << endl;
	else if (r<2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
}


Measured memory_bytes: 256
fn main() {
    let (n, a, b) = {
        let v = read_vec::<u32>();
        (v[0], v[1], v[2])
    };

    let mut total = 0;
    for i in 1..n+1 {
        let mut sum = 0;
        let mut d = i;
        while d / 10 != 0 {
            sum += d % 10;
            d = d / 10;
        }

        sum += d;
        if a <= sum && sum <= b {
            total += i;
        }
    }

    println!("{}", total);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <string>

using namespace std;
int main()
{
	while (true){
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1) {
					cout << "#";
				}else{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3088
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next()

  def solve(s: String): Boolean = {
    if (s.isEmpty) {
      true
    } else if (s.endsWith("dream")) {
      solve(s.dropRight(5))
    } else if (s.endsWith("dreamer")) {
      solve(s.dropRight(7))
    } else if (s.endsWith("erase")) {
      solve(s.dropRight(5))
    } else if (s.endsWith("eraser")) {
      solve(s.dropRight(6))
    } else {
      false
    }
  }

  if (solve(s)) {
    println("YES")
  } else {
    println("NO")
  }
}


Measured memory_bytes: 58188
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 100000000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N;
ll a[SIZE];
struct edge{
	int to;
	ll cap;
	int rev;
};


vector<edge> G[SIZE];
bool used[SIZE];

//グラフ追加: from -> to (cap)
void add_edge(int from, int to, ll cap){
	G[from].push_back((edge){to,cap,(int)G[to].size()});
	G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

ll dfs(int v, int t, ll f){
	if(v==t)return f;
	used[v] = true;
	for(int i=0;i<G[v].size();i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap>0){
			ll d = dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

//s->tのmaxフロー
ll max_flow(int s,int t){
	ll flow = 0;
	for(;;){
		memset(used,0,sizeof(used));
		ll f = dfs(s,t,INF);
		if(f==0)return flow;
		flow += f;
	}
}
int main()
{
	cin >> N;
	ll u = 0;
	rep(i,1,N+1){
		cin >> a[i];
		if(a[i]>=0){
			add_edge(0,i,a[i]);
			u += a[i];
		}else add_edge(i,N+1,-a[i]);
		for(int j=i;j<=N;j+=i){
			add_edge(j,i,INF);
		}
	}
	ll ans = max_flow(0,N+1);
	cout << u-ans << endl;
	return 0;
}


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

const int MAX_N = 100001;

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

  int N, K;
  int A[MAX_N];
  bool leaf[MAX_N];
  int dist[MAX_N];
  fill_n(leaf, MAX_N, true);
  fill_n(dist, MAX_N, 1e8);

  cin >> N >> K;
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];
    if ( A[i] != 0 ) leaf[A[i]-1] = false;
  }

  queue< pair<int, int> > q;
  for ( int i = 0; i < N; i++ ) {
    if ( leaf[i] ) q.push(pair<int, int>(i, 0));
  }

  while ( !q.empty() ) {
    pair<int, int> p = q.front(); q.pop();
    int n = p.first, cost = p.second;
    //cout << n << " " << cost << endl;
    if ( dist[n] <= cost ) continue;
    dist[n] = cost;
    q.push(pair<int, int>(A[n]-1, cost+1));
  }

  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( dist[i] < K || A[i] == 0 ) {
      ans++;
      //cout << i << endl;
    }
  }

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

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

int main() {
    int N; cin >> N; 
    int ans = 0;
    for (int i = 1; i <= N; i+=2) {
        int cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 100100;

    vector<pii> adj[maxN];
    ll vis[maxN], col[maxN];

    void dfs(ll x, ll val){
        vis[x] = 10;
        col[x] = val%2;
        trav(i, adj[x]) if(!vis[i.fst]) {
            if(i.snd%2) dfs(i.fst, val+1);
            else dfs(i.fst, val);
        }
    }

    void solve() {
        ll n, x, y, z;
        cin >> n;
        rep(i, n-1) { 
            cin >> x >> y >> z;
            adj[x].pb({y, z});
            adj[y].pb({x, z});
        }
        dfs(1, 0);
        repA(i, 1, n) cout << col[i] << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
     /*
      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
      #endif
     */
      //te
      solve();
      return 0;
    } 

Measured memory_bytes: 14720
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

int main()
{
	int a, b;
	cin >> a >> b;

	int c;
	if (a <= 5)
	{
		c = 0;
	}
	else if (a <= 12)
	{
		c = b / 2;
	}
	else
	{
		c = b;
	}


	cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s=="Sunny")
        cout << "Cloudy";
    else if (s=="Cloudy")
        cout << "Rainy";
    else cout << "Sunny";
}

// https://atcoder.jp/contests/abc141/tasks/abc141_a

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

int main()
{
    i64 n;
    cin >> n;
    vector<i64> a(n);
    for (i64 i = 0; i < n; i++)
        cin >> a[i];
    vector<vector<i64>> dp(n + 1, vector<i64>(2, -1e18));
    dp[0][0] = 0;
    for (i64 i = 0; i < n; i++)
    {
        dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
        dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
    }
    cout << dp[n][0] << endl;
    return 0;
}


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


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

    int ans=K;
    for(int i=0; i<N-1; i++) ans*=(K-1);
    
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;

int main(){

    int N;
    cin >> N;

    vector <int> a(3 * N);
    for (int i = 0; i < 3 * N; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    long long ans = 0;
    for (int i = N; i <= 3 * N - 2; i += 2){
        ans += a[i];
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
using System;

namespace AtCoder
{
    class B_Coins_087
    {
        public static void Main()
        {
            var coin500Num = int.Parse(Console.ReadLine());
            var coin100Num = int.Parse(Console.ReadLine());
            var coin50Num = int.Parse(Console.ReadLine());
            var totalPrice = int.Parse(Console.ReadLine());
            
            Console.WriteLine(Count(coin500Num, coin100Num, coin50Num, totalPrice));
        }

        private static int Count(int _coin500Num, int _coin100Num, int _coin50Num, int _totalPrice)
        {
            var count = 0;
            for (var a = 0; a <= _coin500Num; ++a)
            {
                var A = a * 500;
                //if (_totalPrice < A) { return count; }

                for (var b = 0; b <= _coin100Num; ++b)
                {
                    var B = b * 100;
                    //if (_totalPrice < B) { return count; }

                    for (var c = 0; c <= _coin50Num; ++c)
                    {
                        var C = c * 50;
                        //if (_totalPrice < C) { return count; }

                        var result = A + B + C;
                        if (result == _totalPrice) { ++count; }
                    }
                }
            }

            return count;
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
int main(void){
	char s[100];
	int i,r=1;
	scanf("%s",s);
	for(i=0;s[i]!='\0';i++){
		if(i%2){
			if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
				r=0;
			}
		}
		else{
			if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
				r=0;
			}
		}
	}
	printf(r?"Yes":"No");
	return 0;
}

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

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
    IOS;
    lln n;
    cin >> n;
    lln mi = INT64_MAX;
    for(lln i=1;i*i<=n;i++){
        if(n % i == 0){
            mi = min(n/i-1 + i-1,mi);
        }
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 3560
def solve():
    import math
    A,B = [int(i) for i in input().split()]
    A_orig = math.ceil(A/0.08)
    A_orig_next = math.ceil((A+1)/0.08)
    B_orig = math.ceil(B/0.1)
    B_orig_next = math.ceil((B+1)/0.1)
    ans = -1
    for i in range(A_orig, A_orig_next):
        if B_orig <= i < B_orig_next:
            ans = i
            break
    print(ans)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9012
#include<bits/stdc++.h>
using namespace std;
int n,p,i,x[1<<17],a;
int main(){
  for(cin>>n;i++<n;){
    cin>>p;
    if(p==i){
      x[i]++;
      a++;
      if(x[i-1])a--,x[i]--;
    }
  }
  cout<<a<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
 
using namespace std;
 
const int MAX = 100000;
 
int main()
{
	int n;
	long int a[MAX] = {0}, b[MAX] = {0};
 
	cin >> n;
 
	for(int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
	}
 
	long int cnt[MAX] = {0};
 
	for(int i = n-1; i >= 0; i--)
	{
		a[i] += cnt[i+1];

		if(a[i] % b[i] != 0)
		{
			//cout << "i = " << i;
			long int res = b[i] - (a[i] % b[i]);
			cnt[i] = cnt[i+1] + res;

			//cout << "cnt = " << cnt[i];
		}else
		{
			cnt[i] += cnt[i+1];
		}
	}
 
	cout << cnt[0] << endl;
 
	return 0;
}

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

int main(){
    string S;
    cin >> S;
    int N = S.length();
    if(N == 1){
        cout << 1 << endl;
        return 0;
    }
    vector<int> dp(200100, 0);
    dp[1] = 1;
    if(S[0] == S[1])dp[2] = 1;
    else dp[2] = 2;
    
    for(int i = 3; i <= N; i++){
        if(S[i - 1] != S[i - 2])dp[i] = dp[i - 1] + 1;
        else dp[i] = dp[i - 3] + 2;
    }
    
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1412
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <cstddef>
#include <cstdint>

template <class T> const T &as_const(const T &v) noexcept { return v; }
class rep {
	const ::std::size_t f, l;

public:
	using value_type = ::std::size_t;
	using reference = value_type;
	class repitr {
		friend rep;
		value_type i;
		repitr(value_type x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		reference operator*() const noexcept { return i; }
		bool operator!=(const repitr x) const noexcept { return i != x.i; }
	};
	explicit rep(value_type first, value_type last) noexcept
		: f(first), l(last) {}
	repitr begin() const noexcept { return repitr(f); }
	repitr end() const noexcept { return repitr(l); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}

using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;

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

template <class T> using vec_alias = ::std::vector<T>;

int main() {
	u32 a, b;
	::std::cin >> a >> b;
	::std::cout << (a&b & 1 ? "Yes" : "No") << ::std::endl;
	return 0;
}


Measured memory_bytes: 764
import java.math.BigDecimal;
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        long N = sc.nextLong();

        long ans = Long.MAX_VALUE;
        long rootN = (long)Math.sqrt(N);
        for (long i = 1; i <= rootN; i++) {
            long muti = N / i;
            if (N % i == 0) {
                ans = Math.min(ans, digit(muti));
            }
        }

        System.out.println(ans);
    }

    private static int digit(long n) {
        return String.valueOf(n).length();
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 +5;
int n;
struct stu
{
    int id;
    int order;
}a[maxn];
bool cmp(stu x,stu y)
{
    return x.order<y.order;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        a[i].id = i;
        a[i].order = x;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n-1;i++)
        cout<<a[i].id<<' ';
    cout<<a[n].id<<endl;
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


MAX_VALUE = 10**5
N, W = ds_in()

# 価値i以上の最小重さ
min_weights = np.ones(MAX_VALUE + 1) * float('inf')
min_weights[0] = 0

total_value = 0
for _ in range(N):
    wv = ds_in()  # [weight, value]
    min_weights[wv[1]:] = np.minimum(min_weights[:-wv[1]] + wv[0],
                                     min_weights[wv[1]:])

for i in range(MAX_VALUE, 0, -1):
    if min_weights[i] <= W:
        print(i)
        exit()


Measured memory_bytes: 16840
#include <iostream>
using namespace std;
int main(void){
    int H,W,i,j;
    cin >> H;
    cin >> W;
    
    while(H != 0 && W != 0){
        for(int i = 0; i < H; i++){
            for(int j =0; j < W; j++){
                cout << "#";
            }
            cout << endl;
        }
        cin >> H;
        cin >> W;
        cout << endl;
    }

}



Measured memory_bytes: 3096
#include <stdio.h>
//Angkanya besar jadi pake long long
int main(){
	long long int n; 
	scanf("%lld",&n);
	long long int num[n]={};
	long long int res=1; //Angka temporary
	for (int i=0;i<n;i++){
		scanf("%lld",&num[i]); //Input 
	}
	for(int i=0;i<n;i++){
		if (num[i]==0){ //Jika ketemu angka 0 di dalam inputan
			printf("0\n"); //Print 0
			return 0; //Terminate Program
		}
		}
	for (int i=0;i<n;i++){
		if(num[i]<=1000000000000000000/res){ //Dicek apakah kurang dari 10^18
			res*=num[i]; //Dikalikan setiap angkanya
		}
		else{
			printf("-1\n"); //Selain itu maka print -1
			return 0; //Terminate program
		}
	}	
		printf("%lld",res); //Print hasil res
		return 0;
	}
	

Measured memory_bytes: 2428
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int x = Integer.parseInt(st.nextToken());

        if(x == 0) {
            pw.println(1);
        } else {
            pw.println(0);
        }

        br.close();
        pw.close();
    }
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    REP(i, Q) cin >> A[i];

    vector<int> point(N, K-Q);
    REP(i, Q) ++point[A[i]-1];
    
    REP(i, N){
        if(point[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
        
    return 0;
}

Measured memory_bytes: 1408
//
// Created by 清水ヒロシ on 2018/11/20.
//
// from ALDS1_2_B: Selection Sort
//

#include <iostream>
#include <vector>

using namespace std;

void selectionSort();
void traceArr(const vector<int> &arr);

int main()
{
    selectionSort();
    return 0;
}

void selectionSort()
{
    int N;
    cin >> N;
    vector<int> arr(static_cast<unsigned long>(N));
    for (int i=0; i<N; ++i) {
        cin >> arr[i];
    }
    int swapTime = 0;
    int min_idx;
    int tmp;
    for (int i=0; i<arr.size(); ++i) {
        min_idx = i;
        for (int j=i+1; j<arr.size(); ++j) {
            if (arr[j] < arr[min_idx]) {
                min_idx = j;
            }
        }
        if (min_idx != i) {
            tmp = arr[min_idx];
            arr[min_idx] = arr[i];
            arr[i] = tmp;
            swapTime ++;
        }
    }
    traceArr(arr);
    cout << swapTime << endl;
}

void traceArr(const vector<int> &arr)
{
    for (int i=0; i<arr.size(); ++i) {
        if (i) {
            cout << " ";
        }
        cout << arr[i];
    }
    cout << endl;
}


Measured memory_bytes: 3092
fun main() {
    val s = next()
    val t = next()
    println(
        if (t.plus(t).contains(s)) {
            "Yes"
        } else {
            "No"
        }
    )
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

Measured memory_bytes: 35632
lines = []
colums = []
 
while True:
  H,W = map(int,input().split())
  if H == 0 and W == 0:
    break
  lines.append(H)
  colums.append(W)
 
for H,W in zip(lines,colums):
  for i in range(H):
    if i == 0 or i == H-1:
      for j in range(W):
        print("#",end="")
    else:
      for j in range(W):
        if 0 < j and j < W-1:
          print(".",end="")
        else:
          print("#",end="")
    print("\n",end="")
  print("\n",end="")


Measured memory_bytes: 7016
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("0"),0;
#define N 500055
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,f[55][55][55],flag[55][55][55],vis[55],tot,z[55],a[55],b[55],ans;
//f[i][j][k] i到j，用<=k的模数能否到达 
int solve(int a,int b,int k){
	if (k==0) return (a==b);
	if (flag[a][b][k]) return f[a][b][k];
	flag[a][b][k]=1;
	return f[a][b][k]=solve(a,b,k-1)|solve(a%k,b,k-1);
}
bool check1(int x,int y,int p){
	F(i,0,50) vis[i]=0;
	vis[x]=1;
	int pd=0;
	D(i,x,y){
		if (vis[i]){
			pd|=solve(i,y,p);
			F(j,1,tot) vis[i%z[j]]=1;
		}
	}
	return pd;
}
bool check(int x){
	memset(vis,0,sizeof(vis));
	int pd=0;
	F(i,1,n){
		pd=check1(a[i],b[i],x-1);
		if (!pd) return 0;
	}
	return 1;
}
signed main(){
	n=read();
	F(i,1,n) a[i]=read();
	F(i,1,n) b[i]=read();
	int pd=1;
	F(i,1,n) if (a[i]!=b[i]) pd=0;
	if (pd) ret;
	if (!check(51)){
		return puts("-1"),0;
	}
	D(i,50,1){
		if (!check(i)) z[++tot]=i,ans+=1LL<<i;
	}
	wrn(ans);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; i++){
        string str = to_string(i);
        if(str[0] == str[4] && str[1] == str[3]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n;
    cin >> n;
    int m = 100, M = -100;
    vs32 a(n);
    rep (i, n)
    {
        cin >> a[i];
        m = MIN(m, a[i]);
        M = MAX(M, a[i]);
    }

    int ans = (int)1e9;
    for (int x = m; x <= M; ++x)
    {
        int sum = 0;
        rep (i, n)
        {
            sum += (a[i] - x) * (a[i] - x);
        }
        ans = MIN(sum, ans);
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

N = gete(int)
h = geta(int)

INF = 1 << 60
dp = [INF] * N
dp[0], dp[1] = 0, abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
                dp[i - 1] + abs(h[i] - h[i - 1]))

print(dp[N - 1])


Measured memory_bytes: 52208
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>

#define MOD 1000000007

using namespace std;

long long dp[1010][1010];
signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    
    int h,w;
    char a[1010][1010];
    cin >> h >> w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> a[i][j];
        }
    }
    dp[1][1] = 1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(i != 1 || j != 1){
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            }
            if(a[i][j] == '#'){
                dp[i][j] = 0;
            }
        }
    }

    cout << dp[h][w] << "\n";
    return 0;
}


Measured memory_bytes: 9088
import sys  
input = sys.stdin.readline

N, M = list(map(int, input().split()))

sk = []
for i in range(M):
    s = list(map(int, input().split()))
    sk.append(s)

p = list(map(int, input().split()))

ans_sum = 0
pre_ = 0
for i1 in [0, 1]:
    for i2 in [0, 1]:
        for i3 in [0, 1]:
            for i4 in [0, 1]:
                for i5 in [0, 1]:
                    for i6 in [0, 1]:
                        for i7 in [0, 1]:
                            for i8 in [0, 1]:
                                for i9 in [0, 1]:
                                    for i10 in [0, 1]:
                                        p_ = [i1, i2, i3, i4, i5, i6, i7, i8, i9, i10]
                                        pre = p_[:N]
                                        if pre == pre_:
                                            break
                                        ans_ = 0
                                        for q in range(M):
                                            ans = 0
                                            for r in range(sk[q][0]):
                                                ans+=pre[sk[q][r+1]-1]
                                            if ans%2 == p[q]:
                                                ans_ +=1
                                        
                                        if ans_ == M:
                                            ans_sum += 1
                                            

                                        pre_ = pre

print(ans_sum)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
lint comb[51][51]={0};
using namespace std;

int main(){
  REP(i,51)comb[i][0]=1;
  FOR(i,1,51){
    FOR(j,1,51)comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
  }
  int N,A,B;
  cin>>N>>A>>B;
  lint v[N];
  REP(i,N){
    cin>>v[i];
  }
  sort(v,v+N,greater<lint>());
  double sum=0;
  REP(i,A){
    sum+=v[i];
  }
  cout<<fixed<<setprecision(7)<<sum/(double)A<<endl;
  int l=0;
  REP(i,N)if(v[i]==v[A-1])l++;
  if(v[A-1]==v[0]){
    lint ans=0;
    FOR(i,A,min(B,l)+1){
      ans+=comb[l][i];
    }
    cout<<ans<<endl;
    return 0;
  }
  int p=N;
  REP(i,N)if(v[i]<v[A-1]){
    p=i;
    break;
  }
  // cerr<<p<<endl;
  cout<<comb[l][p-A]<<endl;
  return 0;
}


Measured memory_bytes: 256
def f(a,i,j,dp):
    if dp[i][j]==-1:
        if i>j:
            return 0

        dp[i][j]=max(a[i]+min(f(a,i+2,j,dp),f(a,i+1,j-1,dp)),
                                a[j]+min(f(a,i+1,j-1,dp),f(a,i,j-2,dp)))
    return dp[i][j]
        
n=int(input())
dp=[[-1 for i in range(n)] for j in range(n)]
a=list(map(int,input().split()))
for i in range(n):
    dp[i][i]=a[i]

for i in range(n-1):
    dp[i][i+1]=max(a[i],a[i+1])

s1=f(a,0,n-1,dp)

print(s1-sum(a)+s1)


Measured memory_bytes: 230256