akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;


//????????±?????¨??????
const int MAX_N = 1000;
int dp[MAX_N + 1][MAX_N + 1];

int solve(string s, string t, int n, int m){
    rep(i,n){
        rep(j,m){
            if(s[i] == t[j]){
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }else{
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    return dp[n][m];
}

int main(){
    int n;
    string s, t;
    cin >> n;
    rep(i,n){
        cin >> s >> t;
        cout << solve(s, t, s.size(), t.size()) << endl;
    }
}

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

int main() {
    int A, B;
    cin >> A >> B;
    int N = B - A + 1;
    vector<int> data(N);
    int answer = 0;
    for(int i =0; i < N; i++){
        data.at(i) = A + i;
        int x, y, z, s;
        x = data.at(i) % 10;
        y = data.at(i) / 10;
        z = y % 10;
        y = data.at(i) / 1000;
        s = y % 10;
        /* cout << x << " " << data.at(i) / 10000  << " " << z << " " << s << endl; */
        if(x == data.at(i) / 10000 && z == s ){
            answer++;
        } 

    }
    cout << answer << endl;
}

Measured memory_bytes: 640
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
 
#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;
 
typedef pair<int, int> P;
 
const int INF = 1e15;
const int MOD = 1e9+7;
 
signed main(){
    int n;
    string st;
    cin >> n >> st;
 
    map<pair<int, string>, int> m;
    rep(s, (1 << n)){
        string a = "";
        string b = "";
        int len = 0;
        rep(i, n){
            if((s >> i) % 2 == 1){
                a.push_back(st[i]);
                len++;
            }else{
                b.push_back(st[i]);
            }
        }
        reverse(b.begin(), b.end());
        a.append(b);
 
        pair<int, string> p = make_pair(len, a);
        if(m.find(p) == m.end()){
            m.emplace(p, 0);
        }
        m[p]++;
    }
 
    int ans = 0;
    rep(s, (1 << n)){
        string a = "";
        string b = "";
        int len = 0;
        rep(i, n){
            if((s >> i) % 2 == 0){
                a.push_back(st[n+i]);
                len++;
            }else{
                b.push_back(st[n+i]);
            }
        }
        reverse(a.begin(), a.end());
        a.append(b);
 
        pair<int, string> p = make_pair(len, a);
        if(m.find(p) != m.end()){
            ans += m[p];
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 35456
#include <algorithm>
#include <iostream>

using namespace std;

int N,K,p[1010];

int main()
{
    cin >> N >> K;
    for(int i = 0;i < N; ++i)
        cin >> p[i];
    sort(p,p + N);
    int ans = 0;
    for(int i = 0; i< K; ++i)
        ans += p[i];
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a;
	cin >> a;
	cout << 3* (a* a) << endl;
	return 0;
}

Measured memory_bytes: 504
import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;
 class Main{
    public static void main(String[] args) {
        MyScanner sc=new MyScanner();
        int n=sc.ni();
        int arr[]=new int[n];
        for(int i=0;i<n;i++)
            arr[i]=sc.ni();
        Arrays.sort(arr);
        int a=0,b=0;
        for(int i=n-1;i>=0;i--){
            if(i%2==0) a+=arr[i];
            else b+=arr[i];
        }
        System.out.println(Math.abs(a-b));
    }


    private static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int ni() {
          return Integer.parseInt(next());
      }
      float nf() {
        return Float.parseFloat(next());
    }
      long nl() {
          return Long.parseLong(next());
      }

      double nd() {
          return Double.parseDouble(next());
      }

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

Measured memory_bytes: 21332
A,B=map(int,input().split())
x=min(A,B)
y=max(A,B)
check=1
##x<=y
#####while break##############
if y%x==0:
    print(y)
#print(root)
else:
    #root=round((x**(1/2)))
    while True:
        through=0
        for i in range(2,int(x)):
            if x%i==0 and y%i==0:
                x/=i
                y/=i
                check*=i 
                through=1
                break
        if through==0:
            break
    print(int(check*x*y))

      

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
const ll DEP = (1LL << 50);
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T x,T y){
    return y ? GCD(y,x%y) : x;
}
ll N,M;
int main(){
    string s; cin >> s;
    map<char,int> mp;
    for(int i = 0; i < s.size(); i++){
        mp[s[i]]++;
    }
    int cnt = 0;
    for(char t = 'A'; t <= 'Z'; t++){
        if (mp[t] > 0 && mp[t] == 2){
            cnt++;
        }
    }
    if (cnt == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G ((c=A[a]+A[P[a]]+C[a])%k?c:0)+M(
typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L i){for(c=G i++)-M(i);i<2e5;i+=i&-i)B[i]+=c;}
L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)
d=I->first,C[d-P[f]?P[d]=f,D(d),n=Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:d:0]=I->second;}
L K(L f){return Z[a=X[f]]>Z[n=X[b]]?n=b,b=f,K(n):abs(M(O[f])-(a-n?-G O[a])-K(P[a]):M(O[b])));}
main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
for(D(0);Z[a=H[P[++n]]-n?n:0];)for(;!O[a];a=H[a],S(*Z=O[c]=++b))X[c=a]=n;
for(cin>>a;cin>>s>>a>>b;S(b=O[a]-1),a=H[a],S(b+1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}


Measured memory_bytes: 37272
n=int(input())
r=list(map(int,input().split()))
rlist=[]
def color(n):
    if n<400:
        return 1
    elif n<800:
        return 2
    elif n<1200:
        return 3
    elif n<1600:
        return 4
    elif n<2000:
        return 5 
    elif n<2400:
        return 6 
    elif n<2800:
        return 7 
    elif n<3200:
        return 8 
    else:
        return 9

for _ in range(n):
    co=color(r[_])
    rlist.append(co)

ans1=len(set(rlist))

if rlist.count(9)==0:
    print(ans1,ans1,sep=" ")

else:    
    if ans1==1:
        print(1,rlist.count(9),sep=" ")

    else:
        print(ans1-1,ans1-1+rlist.count(9),sep=" ")

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

int main(){
	string sa,sb,sc;
	getline(cin,sa);
	getline(cin,sb);
	int i,j=0,k=0;
	for(i=0;i<sa.size()+sb.size();i++){
		if(i%2==1){
			sc+=sb[j++];
		}else{
			sc+=sa[k++];
		}
	}
	cout<<sc;
	return 0;
}


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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    if (dist[i][j] != d) continue;
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9536
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, cnt[100][100];
char c[100];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    for (char ch = 'a'; ch <= 'z'; ch++) c[ch-'a'] = ch;
    rep(i, 0, n) {
        string s;
        cin >> s;
        rep(j, 0, s.size()) {
            rep(k, 0, 26) {
                if (s[j] == c[k]) cnt[i][k]++;
            }
        }
    }
    rep(i, 0, 26) cnt[n][i] = INF;
    rep(i, 0, n) {
        rep(j, 0, 26) {
            cnt[n][j] = min(cnt[i][j], cnt[n][j]);
        }
    }
    vector<char> ans;
    rep(i, 0, 26) {
        if (cnt[n][i] == 0) continue;
        else {
            rep(j, 0, cnt[n][i]) {
                ans.pb(c[i]);
            }
        }
    }
    sort(ans.begin(), ans.end());
    for (auto itr = ans.begin(); itr != ans.end(); itr++) 
        cout << *itr;
    cout << endl;
    return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  ll n,k; cin >> n >> k;
  vl a(n);
  rep(i,n)cin>>a[i];
  vl res(n);
  vl visit(n);
  vl dest;
  ll next = 0;
  if(k <= n){ //kがn以下のときはシミュレート
      rep(i,k){
      next = a[next];
      next--;
      }
      out(next+1);
      return 0;
  }
  else{
    //n回実効する
    visit[0] = true;
    dest.emplace_back(1);
    rep1(i,n+1){
      next = a[next];
      dest.emplace_back(next); //i回目に訪れた場所
      next--;
      if(visit[next] || next == 0){
        
        if(next == 0){ //町1だったら
          out(dest[k%i]);
          break;
        }
        ll dif = i-visit[next]; //周期を求める
        k-=visit[next];
        ll idx = k % dif;
        out(dest[idx+visit[next]]);
        break;
      }
      else visit[next] = i;
    }
  }
}

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

int main() {
    const int MAX = 300000;
    bool isPrime[MAX];
    fill_n(isPrime, MAX, true);
    isPrime[0] = false;
    isPrime[1] = false;
    for (int i = 4; i < MAX; i += 2) {
        isPrime[i] = false;
    }
    for (int i = 3; i * i <= MAX; i += 2) {
        if (isPrime[i]) {
            for (int j = i * 2; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int res = 0;
        for (int i = n + 1; i <= n * 2; i++) {
            if (isPrime[i]) {
                res++;
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 0
import Data.Functor ((<$>))
import Data.List (sort)

readLine :: Read a => String -> [a]
readLine = map read . words

printList :: Show a => [a] -> IO ()
printList = putStrLn . unwords . map show

main :: IO ()
main = do
  ls <- init . lines <$> getContents
  mapM_ (printList . sort . (readLine :: String -> [Int])) ls



Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    
    if(H%h==0 and W%w==0){
        cout<<"No"<<endl;
        return 0;
    }
    
    int tmp1=(H/h)*(W/w),tmp2=H*W-(H-H%h)*(W-W%w);
    int num=(tmp1+tmp2-1)/tmp2+1;
    
    vector<vector<int>> ans(H,vector<int>(W));
    cout<<"Yes"<<endl;
    rep(i,H){
        rep(j,W){
            if((i+1)%h==0 and (j+1)%w==0){
                ans.at(i).at(j)=-num*(h*w-1)-1;
            }else{
                ans.at(i).at(j)=num;
            }
            if(j!=W-1)cout<<ans.at(i).at(j)<<' ';
            else cout<<ans.at(i).at(j)<<endl;
        }
    }
}

Measured memory_bytes: 3328
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

res = 99999999
num = 0
for i in range(n):
    temp = t - h[i] * 0.006
    if res >= abs(temp - a):
        res = abs(temp - a)
        ans = i + 1

print(ans)


Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

// var rdr = bufio.NewReaderSize(os.Stdin, 100000)
var rdr *bufio.Reader

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	solve()
}

func solve() {
	// ABC093C
	in := nextInt
	Is := []int{in(), in(), in()}
	sort.Ints(Is)

	pat := 0
	for _, i := range Is {
		pat += i % 2
	}
	// println("pat is", pat)

	ans := 0
	if pat == 0 {
		ans = (Is[2]-Is[1])/2 + (Is[2]-Is[0])/2
	} else if pat == 1 {
		odd := 0
		even := make([]int, 0, 2)
		for _, i := range Is {
			if i%2 == 1 {
				odd = i
			} else {
				even = append(even, i)
			}
		}
		t := (even[1] - even[0]) / 2
		if even[1] > odd {
			t += (even[1]-odd+1)/2 + 1
		} else {
			t += odd - even[1]
		}

		ans = t
	} else if pat == 2 {
		even := 0
		odd := make([]int, 0, 2)
		for _, i := range Is {
			if i%2 == 0 {
				even = i
			} else {
				odd = append(odd, i)
			}
		}
		t := (odd[1] - odd[0]) / 2
		if odd[1] > even {
			t += (odd[1]-even+1)/2 + 1
		} else {
			t += even - odd[1]
		}

		ans = t
	} else {
		ans = (Is[1] - Is[0]) / 2
		ans += Is[2] - Is[1]
	}

	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func readLine() string {
	buf := make([]byte, 0, 100000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextI64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func maxi64(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func updateMax(a *int, b int) {
	if *a < b {
		*a = b
	}
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func mini64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func updateMin(a *int, b int) {
	if *a > b {
		*a = b
	}
}

func absi64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func anser(b bool, y string, n string) string {
	if b {
		return y
	}
	return n
}

Measured memory_bytes: 640
#include <stdio.h>
 int main(){
        int sum,avg,i,j,k;
        int a[100] = {0};
        int b[100] = {0};
        i=0;
        char op;
        while(scanf("%d%c%d",&a[i],&op,&b[i]) != EOF){
                i++;
                }
        for(j=0;j<i;j++){
                sum += a[j] * b[j];
                avg += b[j] * 10;
        }
        avg = (avg/i+5)/10;
        printf("%d\n%d\n",sum,avg);
return 0;
}

Measured memory_bytes: 596
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_1_C
# ここに来てめちゃくちゃ簡単になったぞどうした？


from math import sqrt


def is_prime(x):
    if x == 1:
        return False
    if x % 2 == 0:
        if x == 2:
            return True
        else:
            return False

    for i in range(3, int(sqrt(x)) + 1):
        if x % i == 0:
            return False

    return True


# load data
N = int(input())
ans = 0
for _ in range(N):
    x = int(input())
    ans += is_prime(x)

print(ans)



Measured memory_bytes: 5672
from collections import Counter

s, t = input(), input()
sc, tc = list(Counter(s).values()), list(Counter(t).values())
sc.sort()
tc.sort()
if sc != tc:
  print('No')
  quit()
ss, tt = s[0], t[0]
for i, j in zip(s, t):
  if i == ss and j == tt:
    continue
  elif  i != ss and j != tt:
    ss, tt = i, j
  else:
    print('No')
    quit()
print('Yes')
    


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define read(x) int x; cin>>x;
#define print(x) for(int i=0; i<(int) x.size(); i++) cout<<x[i]<<" "; cout<<endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;

const ll INFLL = (ll) 1e16;
const int INF = (int) 1e8;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	read(a) read(b) read(t)
	int ans = (t/a)*b;
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = a*b*((c-c/2*2));
  ans = min(ans, b*c*(a-a/2*2));
  ans = min(ans, c*a*(b-b/2*2));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}


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

  vector<vector<ll>> table(10, vector<ll>(10));

  repp(i, 1, N) {
    string n = to_string(i);
    int head = n[0] - '0';
    int tail = n[len(n) - 1] - '0';
    table[head][tail]++;
  }

  ll ans = 0;
  repp(i, 1, 9) {
    repp(j, 1, 9) {
      ans += table[i][j] * table[j][i];
    }
  }
  cout << ans << "\n";
}

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

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

    if(b < 10){
    num = a * 10 + b;
    if(floor(sqrt(num)) == ceil(sqrt(num))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    }


    if(b >= 10  && b < 100){
    num = a * 100 + b;
    if(floor(sqrt(num)) == ceil(sqrt(num))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    }


    if(b == 100){
    num = a * 1000 + b;
    if(floor(sqrt(num)) == ceil(sqrt(num))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    }
    return 0;

}

Measured memory_bytes: 3708
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
int main(){
    int n,x,m,s=0,t=999999;
    cin>>n>>x;
    rep(i,0,n) {
        cin>>m;
        s+=m;
        if(t>m) t=m;
    }
    s=x-s;
    int cnt=0;
        while(s-t>=0){
            s-=t;
            cnt++;
    }
    cout<<n+cnt;
}

Measured memory_bytes: 256
<?php

$rect = 0;
$dia = 0;
while($line = fgets(STDIN)){
	$arr = explode(",", $line);
	$v1 = intval($arr[10]);
	$v2 = intval($arr[11]);
	$s = 0;
	for($i = 0; $i < 10; $i++){
		$s += intval($arr[$i]);
	}
	
	$x = $v1*$s/($v1 + $v2);
	$s = 0;
	for($i = 0; $i < 10; $i++){
		$s += $arr[$i];
		if($x <= $s){
			break;
		}
	}
	$i++;
	echo $i."\n";
}

Measured memory_bytes: 15108
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

const ll mod = 1000000007;
const int N = 2e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
string a, b, s;
int main() {
	while(~scanf("%d", &n)) {
		s.clear(); a.clear(); b.clear();
		rep(i, 1, n + 1) s += (i + '0');
		rep(i, 1, n + 1) {
			int x; scanf("%d", &x);
			a += (x + '0');
		}
		rep(i, 1, n + 1) {
			int x; scanf("%d", &x);
			b += (x + '0');
		}
		// dd(s);dd(a);de(b);
		int u, v;
		if(a == s) u = 1;
		if(b == s) v = 1;
		int cnt = 2;
		while(next_permutation(all(s))) {
			if(s == a) u = cnt;
			if(s == b) v = cnt;
			cnt++;
		}
		printf("%d\n", abs(u-v));
	}
    return 0;
}


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
     ifstream in("input.txt");
     cin.rdbuf(in.rdbuf());
  //*/
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  int ans = 0;
  for(int i = 0; i < N; i++){
    cin >> m[i];
    X -= m[i];
    ans++;
  }
  sort(m.begin(), m.end());
  cout << ans + X/m[0] <<endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    ll X,A,B;
    cin >> X >> A >> B;
    if(B-A <= 0){
        cout << "delicious";
    }else{
        if(B-A <= X){
            cout << "safe";
        }else{
            cout << "dangerous";
        }
    }
    return 0;
}

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

int main() {
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    map<int, int> x;
    for (int i = 0; i < n; i++) {
        int s;
        cin >> s;
        x[s]++;
    }
    int ans = 0;
    for (auto s : x) {
        if (s.se == s.fi) continue;
        if (s.se > s.fi) {
            ans += s.se - s.fi;
        } else {
            ans += s.se;
        }
    }
    cout << ans;
    return 0;
} 

Measured memory_bytes: 4736
#include<iostream>
#include<map>
#include<array>

using DiceLabel = std::map<int, int>;

class Dice {

  public:
    Dice(DiceLabel dice_arg) {
      dice = dice_arg;
    }

    int top() {
      return dice[top_index];
    }

    int front() {
      return dice[front_index];
    }

    int left() {
      return dice[left_index];
    }

    int right() {
      return dice[right_index];
    }

    void roll_east() {
      int before_right = dice[right_index];

      dice[right_index] = dice[top_index];
      dice[top_index] = dice[left_index];
      dice[left_index] = dice[bottom_index];
      dice[bottom_index] = before_right;
    }

    void roll_west() {
      int before_left = dice[left_index];

      dice[left_index] = dice[top_index];
      dice[top_index] = dice[right_index];
      dice[right_index] = dice[bottom_index];
      dice[bottom_index] = before_left;
    }

    void roll_north() {
      int before_back = dice[back_index];

      dice[back_index] = dice[top_index];
      dice[top_index] = dice[front_index];
      dice[front_index] = dice[bottom_index];
      dice[bottom_index] = before_back;
    }

    void rotate_clockwise() {
      int before_back = dice[back_index];

      dice[back_index] = dice[left_index];
      dice[left_index] = dice[front_index];
      dice[front_index] = dice[right_index];
      dice[right_index] = before_back;
    }

    void roll(int afterTop, int afterFront) {
      if(afterTop == left()) {
        roll_east();
      }
      if(afterTop == right()) {
        roll_west();
      }
      while(!(top() == afterTop)) {
        roll_north();
      }
      while(!(front() == afterFront)) {
        rotate_clockwise();
      }
    }

  private:
    const int top_index = 1;
    const int right_index = 3;
    const int bottom_index = 6;
    const int left_index = 4;
    const int front_index = 2;
    const int back_index = 5;
    DiceLabel dice;
};


const int DiceNum = 2;
const int DiceFaceNum = 6;

int main() {
  DiceLabel inner_dice1, inner_dice2;

  for(int i = 1; i <= DiceFaceNum; i++) {
    std::cin >> inner_dice1[i];
  }
    for(int i = 1; i <= DiceFaceNum; i++) {
    std::cin >> inner_dice2[i];
  }

  Dice dice1(inner_dice1), dice2(inner_dice2);

  dice2.roll(dice1.top(), dice1.front());


  std::string result;
  if(dice1.right() == dice2.right()) {
    result = "Yes";
  } else {
    result = "No";
  }

  std::cout << result << std::endl;
}



Measured memory_bytes: 3228
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=2e5+5,inf=0x3f3f3f3f;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
inline int max(R int x,R int y){return x>y?x:y;}
inline int min(R int x,R int y){return x<y?x:y;}
int d1[N],d2[N],d3[N],d4[N],sz[N],fa[N];
ll res;char s[N];int n;
void dfs1(int u){
	sz[u]=(s[u]=='1'),d3[u]=sz[u]?0:inf;
	go(u)if(v!=fa[u]){
		fa[v]=u,dfs1(v),sz[u]+=sz[v],cmax(d1[u],d1[v]+1);
		if(sz[v])cmin(d3[u],d1[v]+1);
	}
}
void dfs2(int u){
	if(fa[u])d4[u]=d2[u]-1;
	R int se=0,fi=0,to=0;
	go(u)if(v!=fa[u]){
		if(d1[v]+1>=fi)to=v,se=fi,fi=d1[v]+1;
		else cmax(se,d1[v]+1);
	}
	go(u)if(v!=fa[u]){
		d2[v]=max(v==to?se:fi,d2[u])+1;
		dfs2(v);
	}
}
int main(){
	scanf("%d",&n);
	for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	scanf("%s",s+1);
	dfs1(1),dfs2(1);
	fp(u,1,n){
		R int mn=min(d3[u],sz[u]==sz[1]?1e9:d2[u]);
		R int mx=max(d1[u],d2[u])-1;
		go(u)cmin(mx,(v==fa[u]?d1[u]:d4[v])+1);
		res+=max(mx-mn+1,0);
	}
	printf("%lld\n",res+1);
	return 0;
}

Measured memory_bytes: 16128
import java.util.Scanner;

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

        if (a + b == 15) {
            System.out.println("+");
        } else if (a * b == 15) {
            System.out.println("*");
        } else {
            System.out.println("x");
        }
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

#define PT pair<int, int>

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


	int N, M;
	cin >> N >> M;
	int to[100001], ne[100001], he[100001] = {};
	rep1(i, M) {
		int u, v;
		cin >> u >> v;
		to[i] = v;
		ne[i] = he[u];
		he[u] = i;
	}
	int S, T;
	cin >> S >> T;

	int D[300004];
	rep(i, 300004) D[i] = 1e9;
	D[3 * S] = 0;

	queue<PT> que;
	que.push(mp(0, 3 * S));
	while (que.size()) {
		PT p = que.front();
		que.pop();
		int i = p.second;
		if (D[i] < p.first) continue;
		int i2 = i / 3;
		for (int j = he[i2]; j; j = ne[j]) {
			int d = D[i] + 1;
			int j2 = to[j] * 3 + (i + 1) % 3;
			if (D[j2] > d) {
				D[j2] = d;
				que.push(mp(d, j2));
			}
		}
	}

	if (D[3 * T] == 1e9) co(-1);
	else co(D[3 * T] / 3);

	Would you please return 0;
}

Measured memory_bytes: 3072
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    ll sum=0;
    ll mi=E;
    ll count=0;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        sum+=a;
        if(a&1){count++; mi=min(mi,a);}
    }
    if(count&1){
        cout<<(sum-mi)/2<<endl;
    }
    else{
        cout<<sum/2<<endl;
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3092
import math
N = int(input())
A = []
B = []

for n in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


answer = 0
for i in reversed(range(N)):
    answer += B[i] * math.ceil((A[i] + answer) / B[i]) - (A[i] + answer)
print(answer)


Measured memory_bytes: 11112
# -*- coding: utf-8 -*-
#D - Cake 123
import sys 
from itertools import product
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X, Y, Z, K = map(int, readline().split())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
C = list(map(int,readline().split()))

AB = []
for a,b in product(A,B):
    AB.append(a+b)

AB = sorted(AB,reverse=True)[:K]
ABC = []
for ab,c in product(AB,C):
    ABC.append(ab+c)
ABC = sorted(ABC,reverse=True)

for i in range(K):
    print(ABC[i])

Measured memory_bytes: 248888
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;

int keta(int a){
    int count=0;
    while(a!=0){
        a/=10;
        count++;
    }
    return count;
}


int main(){
    long long int n,k,s; //オーバーフローもたぶん大丈夫
    cin>>n>>k>>s;
    vector<long long int> a(n);
    for(int i=0;i<n;i++){
        if(i<k){
            a.at(i)=s;
        }
        else{
            if(s==pow(10,9)){
                a.at(i)=1;
            }
            else{
                a.at(i)=s+1;
            }
        }
    } //二つ以上選ぶと必ずsを超える、sの項がちょうどk個ある

    for(int i=0;i<n-1;i++){
        cout<<a.at(i)<<' ';
    } //ほとんどACだったから出力形式はあってるはず
    cout<<a.at(n-1)<<endl;

    return 0;
} //カモンAC

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

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

    vector<int> cnt(3);
    for(auto x:S){
        if(x=='a') cnt[0]++;
        else if(x=='b') cnt[1]++;
        else cnt[2]++;
    }
    VRSORT(cnt);
    if(cnt[0]==cnt[1] && cnt[1]==cnt[2]) cout<<"YES"<<endl;
    else if(cnt[0]==cnt[1]+1 && cnt[1]+1==cnt[2]+1) cout<<"YES"<<endl;
    else if(cnt[0]==cnt[1] && cnt[1]==cnt[2]+1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
#define int long long
using namespace std;
using VI = vector<int>;
unordered_map<int, int> poz;
unordered_set<int> viz;
VI t, nod;
int n, m, x(1), pi;
long long k;
int32_t main() {
    DAU
    cin >> n >> k;
    t = VI(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> t[i];
    nod.emplace_back(0);
    for (m = 1 ;; ++m) {
        if (m == k+1) {
            cout << x;
            PLEC
        }
        nod.emplace_back(x);
        poz[x] = m;
        viz.emplace(x);
        x = t[x];
        if (viz.count(x))
            break;
    }
    pi = m - poz[x] + 1;
    k -= poz[x] - 1;
    cout << nod[k % pi + poz[x]];
    PLEC
}


Measured memory_bytes: 19904
#include <stdio.h>
#include <random>
int D;
int c[26];
int l[367][26];
int s[366][26];
int t[366];
long long m = 10000000;
int  p, q, d, k, pp, dd, f;
int ans, bans;
unsigned long long a;
int main() {
	scanf("%d", &D);
	for (int i = 0; i < 26; i++) {
		scanf("%d", c + i);
	}
	for (int i = 1; i <= D; i++) {
		for (int j = 0; j < 26; j++) {
			scanf("%d", s[i] + j);
		}
	}
	std::mt19937_64 rd(468);
	for (int i = 1; i <= D; i++) {
		a = rd();
		t[i] = a % 26;
	}
	for (int i = 1; i <= D; i++) {
		ans += s[i][t[i]];
		for (int j = 0; j < 26; j++) {
			l[i][j] = l[i - 1][j] + 1;
		}
		l[i][t[i]] = 0;
		for (int j = 0; j < 26; j++) {
			ans -= c[j] * l[i][j];
		}
	}
	for (long long i = 0; i < m; i++) {
		a = rd();
		if (f) {
			d = dd;
			q = pp;
		}
		else {
			d = a % D + 1;
			q = a % 26;
		}
		p = t[d];
		if (p != q) {
			bans = ans;
			t[d] = q;
			ans -= s[d][p];
			ans += s[d][q];
			k = d;
			while (l[k][q] && k <= D) {
				ans -= c[q] * (k - d - l[k][q]);
				l[k][q] = k - d;
				k++;
			}
			k = d;
			do {
				ans -= c[p] * (l[k - 1][p] + 1 - l[k][p]);
				l[k][p] = l[k - 1][p] + 1;
				k++;
			} while (l[k][p] && k <= D);
			a = rd();
			f = 0;
			if (ans < bans && (a % (m * m)) < 2 * m * i - i * i + 10000) {
				f = 1;
				pp = p;
				dd = d;
			}
		}
	}
	for (int i = 1; i <= D; i++) {
		printf("%d\n", t[i] + 1);
	}
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);
    rep(i, n) cin >> t[i] >> x[i] >> y[i];

    bool ok = true;
    int time = 0, dx = 0, dy = 0;
    rep(i, n)
    {
        time = t[i] - time;
        dx = abs(x[i] - dx);
        dy = abs(y[i] - dy);

        if (time % 2 != (dx + dy) % 2 || dx + dy > time)
        {
            ok = false;
        }
    }

    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 4484
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(auto&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(auto&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(auto&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(auto&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(auto&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}};
template<typename S,typename T,typename U>
auto& operator<<(auto& o,TRI<S,T,U>& t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 100005;

int a[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    int mn = *min_element(a, a+n), mx = *max_element(a, a+n);
    if(mx-mn>1){
        cout << "No\n";
    }else if(mx == mn){
        if(mx == n-1 || n/2 >= mx){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }else{
        int cnt = 0;
        rep(i,n){
            if(mn == a[i]) cnt++;
        }
        if(cnt <= mn && mn-(cnt-1) <= (n-cnt)/2){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }
    return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

A, B, H, M = read_ints()

import numpy as np
thetaA = (H + M / 60) / 12 * 2 * np.pi
thetaB = (M / 60) * 2 * np.pi

# print(H / 12, M / 60, H / 12 - M / 60)
theta = thetaA - thetaB if thetaA > thetaB else thetaB - thetaA
if theta > np.pi:
    theta = 2 * np.pi - theta

ans2 = (A ** 2) + (B ** 2) - (2 * A * B * np.cos(theta))
print(np.sqrt(ans2))


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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    int ans=0,cnt,p;
    for(ll i=2; i*i<n; i++){
        if(n%i==0){
            cnt=0;
            p=i;
            while(n%p==0){
                n/=p;
                p *= i;
                cnt++;
            }
            ans += cnt;
            while(n%i==0){
                if(n%p==0) n/=p;
                else p/=i;
            }
        }
        if(i!=2) i++;
    }
    if(n!=1) ans++;
    print(ans);
    return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define repm(i, m, n) for (int i = (m); i < (n); i++)
#define rep_rev(i, n) for (int i = int (n); i >= 0; i--)
typedef long long ll;
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;
	return 0;
}

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

    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i,n){
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    int tmp;
    rep(i,n){
        if(s[i] == x){
            tmp = i;
        }
    }
    int ans = 0;
    for (int i = tmp + 1; i < n;i++){
        ans += t[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
from itertools import *
cnt=0
for i in list(permutations(range(1,n+1))):
    if list(i) == p:
        p_cnt=cnt
    if list(i) == q:
        q_cnt=cnt
    cnt+=1
print(abs(p_cnt-q_cnt))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
string s;
int dp[10001][101][2];
int f(int pos,int ss,int d,int tight){
   int ub=tight?s[pos]-'0':9;
   if(dp[pos][ss][tight]!=-1)return dp[pos][ss][tight];
   int x=s.size();
   if(pos==x-1){
      int cnt=0;
      for(int i=0;i<=ub;i++){
         //s[pos]+i-'0';
         if((i)%d==ss)cnt+=1;
      }
      return cnt;
   }
   int cnt=0;
   for(int i=0;i<=ub;i++){
      cnt=(cnt+f(pos+1,(d+ss-i%d)%d,d,tight&(i==ub)))%mod;
   }
   return dp[pos][ss][tight]=cnt;
}
int32_t main(){
cin>>s;
int d;cin>>d;
memset(dp,-1,sizeof(dp));
int ans=f(0,0,d,1);
ans-=1;
cout<<(ans+mod)%mod<<endl;
}

Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  ll N, Y;
  cin >> N >> Y;

  repp(i, 0, N) {
    repp(j, 0, N - i) {
      int k = N - i - j;
      ll sum = i * 10000 + j * 5000 + k * 1000;

      if (sum == Y) {
        cout << i << ' ' << j << ' ' << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 256