akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = nextIntArray(sc, N);

		sc.close();

		int all = 0;
		for (int a : A) {
			all += a;
		}

		int num = 0;

		for (int a : A) {
			if (a*4*M >= all) {
				num++;
			}
		}

		if (num >= M) {
			out.println("Yes");
		} else {
			out.println("No");
		}

	}

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

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 23764
#include <stdio.h>

int main(){
    int a,b,c,x,y,z;

    scanf("%d %d %d",&a,&b,&c);

    x =a;
    y = b;
    z = c;

    x = b;
    y =a;
    

    x = c;
    z = b;




    printf("%d %d %d\n",x,y,z);


    return 0;
}


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

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	map<string,int> mp;
	mp["AC"]=0;
	mp["WA"]=0;
	mp["TLE"]=0;
	mp["RE"]=0;
	int test;
	cin>>test;
	string s;
	while(test--){
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<"\n";
	cout<<"WA x "<<mp["WA"]<<"\n";
	cout<<"TLE x "<<mp["TLE"]<<"\n";
	cout<<"RE x "<<mp["RE"]<<"\n";
	

}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
  vector<int> a = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
  int k;
  cin >> k;
  cout << a.at(k-1) << endl;
}


Measured memory_bytes: 3608
import scala.io.StdIn
object Main extends App {
  val N = StdIn.readLine().toInt
  val cakeCombinations = for {
    a <- 0 to N
    b <- 0 to N-1
    if 4 * a + 7 * b == N
  } yield (a, b)
  println(if (cakeCombinations.isEmpty) "No" else "Yes")
}


Measured memory_bytes: 27460
from heapq import heappop, heappush

while True:
    n, m = map(int, input().split())
    if not n:
        break

    num_stones = 0
    row_stones = [None] * n
    edges = [None] * n
    visited = [None] * n
    for row in range(n):
        (num, *stones) = map(int, input().split())
        row_stones[row] = list(zip(*[iter(stones)] * 2))
        edges[row] = [None] * num
        visited[row] = [1] * num

    for row, stones in enumerate(row_stones):
        next_stones = [row_stones[row + j] if row + j < n else [] for j in (1, 2)]
        for i, (column1, slip1) in enumerate(stones):
            edges[row][i] = [{(abs(column1 - column2) * (slip1 + slip2), j)
                              for j, (column2, slip2) in enumerate(next_stones[k])} for k in (0, 1)]

    queue = [(0, 0, -m, i) for i in range(len(row_stones[0]))]
    if m:
        queue.extend((0, -1, -m + 1, i) for i in range(len(row_stones[1])))

    while queue:
        total_risk, row, remains, i = heappop(queue)
        row = -row
        if row == n - 1 or (remains and row == n - 2):
            print(total_risk)
            break
        if visited[row][i] <= remains:
            continue
        visited[row][i] = remains
        next_stones = edges[row][i]
        for risk, j in next_stones[0]:
            heappush(queue, (total_risk + risk, -row - 1, remains, j))
        if remains:
            for risk, j in next_stones[1]:
                heappush(queue, (total_risk + risk, -row - 2, remains + 1, j))

Measured memory_bytes: 86508
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

const ll mod = 1000000007ll;
const ll nyaaaa = 407182070ll;
ll A[2002002], B[2002002]={1};
ll modpow(ll x, ll y, ll m){
    if(y == 0ll)return 1ll;
    ll res = 1ll, tmp = x;
    while(y){
        if(y&1) res = res * tmp % m;
        tmp = tmp * tmp % m;
        y >>= 1;
    }
    return res;
}
ll pom(ll x, ll y){return modpow(x, y, mod);}
void nyan(){
    ll i = 1;
    for(; i<=2000000; i++){
        B[i] = B[i-1] * i % mod;
    }i--;
    A[i] = nyaaaa;
    for(;i>0; i--){
        A[i-1] = A[i] * i % mod;
    }
}
int k;
char s[1001001];
int main(){
    nyan();
    scanf("%d%s", &k, s);
    int l = strlen(s);
    ll ans = 0;
    for(int i=0; i<=k; i++){
        ans += pom(26, k-i) * pom(25, i) % mod * B[l+i-1] % mod * A[l-1] % mod * A[i] % mod;
        ans %= mod;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 33940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;

int main() {
  string S;
  cin>>S;
  
  string X=S.substr(0,2);
  string Y=S.substr(2,2);
  
  int x=stoi(X);
  int y=stoi(Y);
  
  // xとyが1-12であるか判定するフラグ
  bool x_m=false;
  bool y_m=false;
  
  if(1<=x && x<=12)
    x_m=true;
  if(1<=y && y<=12)
    y_m=true;
  
  if(x_m==true && y_m==false)
    cout<<"MMYY"<<endl;
  else if(x_m==false && y_m==true)
    cout<<"YYMM"<<endl;
  else if(x_m==true && y_m==true)
    cout<<"AMBIGUOUS"<<endl;
  else if(x_m==false && y_m==false)
    cout<<"NA"<<endl;
  
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define N 100010
#define inf 1000000000
using namespace std;

struct tt{int l, r, mn, mnp, f; vector<int>a;}t[N*2];
struct edge{int x, y, next;}a[N*2];
struct bb{int x, y;}b[N];
int n, l, p[N], x, y, pos[N], c[N], led[N], fa[N], def[N], size[N], flag[N];

inline void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}
inline void dfs1(int x){
	size[x]=1;
	for(int i=p[x]; i; i=a[i].next)if(fa[x]!=a[i].y){
		fa[a[i].y]=x; def[a[i].y]=def[x]+1; dfs1(a[i].y); size[x]+=size[a[i].y];
	}
}
inline void dfs2(int x){
	l++; pos[x]=l; c[l]=x;
	int mx=0, v=0;
	for(int i=p[x]; i; i=a[i].next)if(fa[x]!=a[i].y&&mx<size[a[i].y]){mx=size[a[i].y]; v=a[i].y;}
	if(v){led[v]=led[x]; dfs2(v);}
	for(int i=p[x]; i; i=a[i].next)if(fa[x]!=a[i].y&&v!=a[i].y){
		led[a[i].y]=a[i].y; dfs2(a[i].y);
	}
}

inline void update(int i){
	if(t[t[i].l].mn<=t[t[i].r].mn){t[i].mn=t[t[i].l].mn; t[i].mnp=t[t[i].l].mnp;}
	else{t[i].mn=t[t[i].r].mn; t[i].mnp=t[t[i].r].mnp;}
}
inline void maketree(int L, int R){
	t[l].l=t[l].r=t[l].f=t[l].mn=0; t[l].mnp=L; t[l].a.clear();
	if(L<R){
		int mid=(L+R)>>1, l1=l;
		l++; t[l1].l=l; maketree(L, mid);
		l++; t[l1].r=l; maketree(mid+1, R);
		update(l1);
	}else if(L==1){t[l].mn=inf;}
}

inline void updatef(int i, int x){t[i].f+=x; t[i].mn+=x;}
inline void pushdown(int i){
	if(t[i].f){updatef(t[i].l, t[i].f); updatef(t[i].r, t[i].f); t[i].f=0;}
}

inline void ins(int i, int a, int b, int id, int c, int L, int R){
	if(a<=L&&R<=b){updatef(i, c); if(c==1)t[i].a.push_back(id); return;}
	pushdown(i);
	int mid=(L+R)>>1;
	if(a<=mid)ins(t[i].l, a, b, id, c, L, mid);
	if(mid<b)ins(t[i].r, a, b, id, c, mid+1, R);
	update(i);
}
inline void ins1(int i, int x, int y, int z){
	int xx, yy;
	while(led[x]!=led[y]){
		xx=led[x]; yy=led[y];
		if(def[xx]>=def[yy]){ins(1, pos[xx], pos[x], i, z, 1, n); x=fa[xx];}
		if(def[xx]<=def[yy]){ins(1, pos[yy], pos[y], i, z, 1, n); y=fa[yy];}
	}
	if(def[x]>def[y])ins(1, pos[y]+1, pos[x], i, z, 1, n);
	if(def[x]<def[y])ins(1, pos[x]+1, pos[y], i, z, 1, n);
}

inline void check(int i, int x, int L, int R){
	while(t[i].a.size()&&flag[t[i].a[t[i].a.size()-1]])t[i].a.pop_back();
	if(t[i].a.size())y=t[i].a[t[i].a.size()-1];
	if(L==R){t[i].mn=inf; return;}
	pushdown(i);
	int mid=(L+R)>>1;
	if(x<=mid)check(t[i].l, x, L, mid);
	else check(t[i].r, x, mid+1, R);
	update(i);
}

int main(){
	scanf("%d", &n);
	l=0; memset(p, 0, sizeof(p));
	for(int i=1; i<=n-1; i++){scanf("%d%d", &x, &y); add(x, y); add(y, x);}
	for(int i=1; i<=n-1; i++)scanf("%d%d", &b[i].x, &b[i].y);
	fa[1]=0; def[1]=1; dfs1(1);
	l=0; led[1]=1; dfs2(1);
	l=1; maketree(1, n);
	for(int i=1; i<=n-1; i++)ins1(i, b[i].x, b[i].y, 1);
	memset(flag, 0, sizeof(flag));
	for(int i=1; i<=n-1; i++){
		if(t[1].mn!=1){printf("NO"); return 0;}
		x=t[1].mnp; check(1, x, 1, n);
		flag[y]=1; ins1(y, b[y].x, b[y].y, -1);
	}
	printf("YES");
	return 0;
}

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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
//  freopen(Task".out", "w", stdout);
  int n, m;
  cin >> n >> m;
  vector<int> ans(n + 1, -1);
  if (n == 1 && m == 0){
    cout << 0;
    exit(0);
  }
  while (m--){
    int pos, d; cin >> pos >> d;
    if (ans[pos] == -1) ans[pos] = d;
    else{
      if (ans[pos] != d){
        cout << -1; exit(0);
      }
    }
  }

  if (ans[1] == 0){
    if (n == 1){
      cout << 0; exit(0);
    } else {
      cout << -1; exit(0);
    }
  }
  for (int i = 1; i <= n; ++i){
    if (ans[i] == -1){
      if (i == 1) cout << 1;
      else cout << 0;
    } else cout << ans[i];
  }
}



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

def make_divisors(n):
    ans = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans += 1
            if i != n // i:
                ans += 1
    return ans

ans = 0
for i in range(1,N+1):
    if (i %2 ==1) and (make_divisors(i) ==8):
        ans += 1

print(ans)

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


int main() {
  int N, K;
  string s;

  cin >> N >> K;
  cin >> s;

  s.at(K - 1) = s.at(K - 1) - 'A' + 'a';

  cout << s << endl;
}
/* 2 10 20 */


Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define Spa putchar(32)
int read()
{
	int s=0,c=getchar(),f=1;
	while(c<48||c>57)
	{
		if(c==45) f=-1;
		c=getchar();
	}
	while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return s*f;
} 
void write(int x)
{
	if(x>=10) write(x/10);
	putchar(x%10+48);
}
void W(int x)
{
	if(x<0) x=-x,putchar(45);
	write(x);
}
int main()
{
	int a=read();int b=read();int c=read();int d=0;
	for(int i=min(a,b);i;--i)
	if(a%i==0&&b%i==0)
	{
		++d;
		if(d==c)
		{
			write(i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "03"
#include"bits/stdc++.h"
using namespace std;
 
#define input_from_file freopen("inp.txt","r",stdin)
#define output_to_file freopen("out.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)

int main() {
	#ifdef LOCAL 
	input_from_file; 
	output_to_file; 
	#endif
   
    fastio;cin.tie(0);cout.tie(0);
	int h,a;
	cin >> h>>a;

	cout<<ceil(float(h)/float(a));
	
	return 0;
}

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

ll ctoi(char c) {
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5;
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  if (c == '0') return 0;
}

int main() {
  string s;
  cin >> s;
  ll D = s.size();
  ll mod[6] = {1, 10, 9, 12, 3, 4};
  
  char c[D];
  for (ll i = 0; i < D; i++) {
    c[i] = s.at(D-1-i);
  }
  
  //i+1桁目まで見た時に、あまりがjになるものの総数dp[i][j]
  ll dp[D][13];
  for (ll j = 0; j < 13; j++) {
    if (c[0] == '?' && j <= 9) {dp[0][j] = 1;}
    else if (c[0] == '?' && 9 < j) {dp[0][j] = 0;}
    else if (c[0] != '?' && ctoi(c[0]) == j) {dp[0][j] = 1;}
    else {dp[0][j] = 0;}
  }
  
  for (ll i = 1; i < D; i++) {
    for (ll j = 0; j < 13; j++) {
      if (c[i] == '?') {
        dp[i][j] = 0;
        for (ll k = 0; k < 10; k++) {
          dp[i][j] += dp[i-1][(j - (k*mod[i % 6]) %13 + 13) %13] % M;
        }
      }
      if (c[i] != '?') {
        dp[i][j] = dp[i-1][(j - (ctoi(c[i])*mod[i % 6]) %13 + 13) %13] % M;
      }
    }
  }
  
  cout << dp[D-1][5] % M << endl;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  map<int,int> m;
  for(int i = 0; i < N; ++i){
    int t;
    cin >> t;
    m[t]++;
  }
  int s = m.size();
  priority_queue<int, vector<int>, greater<int> > p;
  for(auto x: m){
    p.push(x.second);
  }
  if(s <= K){
    cout << 0 << endl;
  }else{
    int res = 0;
    int t = s - K;
    for(int i = 0; i < t; ++i){
      res += p.top();
      p.pop();
    }
    cout << res << endl;
  }


}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    int H,W,K;
    cin>>H>>W>>K;
    vector<vector<int>> cake(H,vector<int>(W));
    vector<int> nums(H);
    int num=1;
    rep(i,H){
        rep(j,W){
            char a;
            cin>>a;
            if(a=='#'){
                cake.at(i).at(j)=num;
                num++;
                nums.at(i)++;
            }
        }
    }
    int fir;
    rep(i,H){
        if(nums.at(i)>0){
            fir=i;
            break;
        }
    }
    vector<int> fline(W);
    int count=0;
    rep(k,W){
        if(cake.at(fir).at(k)>0){count++;}
        fline.at(k)=max(count,1);
    }
    rep(i,H){
/*rep(j,W){
    cout<<fline.at(j)<<" ";
}
cout<<endl;*/
        if(nums.at(i)>0 && i>fir){
            int c;
            c=fline.at(W-1);
            int c2=c+1;
            rep(k,W){
                if(cake.at(i).at(k)>0){c++;}
                fline.at(k)=max(c,c2);
            }
        }
        rep(i,W){
            cout<<fline.at(i)<<" ";
        }
        cout<<endl;
    }
}

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

s = input().rstrip()
l = [0]*len(s)
k=0
for i in range(1,len(s)-1):
    if s[i] == s[i-1] and l[i-1] == 0:
        l[i]=1
        l[i+1]=1
        
if len(s) >1 and s[-1] == s[-2] and l[-2] == 0:
    l[-2] = 1
    l[-1]=1
print(len(s)-sum(l)//2)


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

int pos;
string s, t;

int main(){
	cin >> s >> t;
	for(pos = s.size() - t.size(); pos >= 0; pos--){
		bool b = true;
		for(int i = 0; i < t.size(); i++){
			if(s[i+pos] != '?' && t[i] != s[i+pos]) b = false;
		}
		if(b) break;
	}
	if(pos != -1){
		for(int i = 0; i < s.size(); i++){
			if(s[i] == '?'){
				if(pos <= i && i < pos + t.size()) s[i] = t[i-pos];
				else s[i] = 'a';
			}
		}
	}
	cout << (pos != -1 ? s : "UNRESTORABLE") << "\n";
}

Measured memory_bytes: 256
def main():
    N = int(input())
    D = list(map(int, input().split()))
    D.append(0)
    h = [0 for _ in range(13)]
    for d in D:
        h[d] += 1
    if h[0] >= 2 or h[12] >= 2:
        return 0
    for i in range(1, 12):
        if h[i] >= 3:
            return 0

    res = 0
    for i in range(2**11):
        L = [0]
        for j in range(1, 12):
            if h[j] == 2:
                L.append(j)
                L.append(24-j)
            if h[j] == 1:
                if i & 2**(j-1) != 0:
                    L.append(j)
                else:
                    L.append(24-j)
        if h[12] == 1:
            L.append(12)
        L.append(24)
        L.sort()
        tres = 25
        for i in range(len(L)-1):
            tres = min(tres, L[i+1]-L[i])
        res = max(res, tres)
    return res


print(main())


Measured memory_bytes: 40944
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
int l=0;
cin>>a;
for (int i=0;i<3;i++){
    if (a[i]=='o')
        l++;
}
if (l==1)
    cout<<"800";

else if (l==2)
    cout<<"900";

else if (l==3)
    cout<<"1000";

else
    cout<<"700";

return 0;
}


Measured memory_bytes: 256
parseInt(s) = parse(Int,s)
function solve()
    N,Q=map(parseInt, split(readline()))
    n=N-2
    r=fill(n,n)
    c=fill(n,n)
    H=W=n+1
    ans = n^2
    for q=1:Q
        qn,x=split(readline())
        x=parseInt(x)-1
        if qn=="1"
            # (1,x)に置く
            if x < W
                for i=x:W-1
                    c[i]=H-1
                end
                W=x
            end
            ans-=c[x]
        else
            # (x,1)に置く
            if x < H
                for i=x:H-1
                    r[i]=W-1
                end
                H=x
            end
            ans-=r[x]
        end
    end
    println(ans)
end

solve()

Measured memory_bytes: 203404
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int n;
vector<vector<pair<ll,ll>>> gra;
vll dist;

int main(){cout<<fixed<<setprecision(10);
           cin>>n;
           gra.resize(n);
           dist.assign(n,-1);
           ll a,b,c;
           rep(i,0,n-1){
             cin>>a>>b>>c;
             a--;b--;
             gra[a].push_back(mp(b,c));
             gra[b].push_back(mp(a,c));
           }
           ll q,k;
           cin>>q>>k;
           k--;
           //bfs
           queue<ll> que;
           dist[k]=0;
           for(auto v:gra[k]){
             dist[v.first]=v.second;
          		 que.push(v.first);
             }
           while(!que.empty()){
            ll p=que.front();
             que.pop();
             for(auto v:gra[p]){
              ll next=v.first,cost=v.second;
              if(dist[next]!=-1)continue;
              dist[next]=dist[p]+cost;
              que.push(next);
             }
           }
           ll x,y;
           rep(i,0,q){
            cin>>x>>y;
             //
             x--;y--;
             cout<<dist[x]+dist[y]<<endl;
           }
}

Measured memory_bytes: 11844
# encoding:utf-8

import itertools as it

def main(values):
	values.sort()
	
	i = 0
	while True:
		if values[1] == values[2]:
			break
		values[0] += 1
		values[1] += 1
		i += 1

	while True:
		if values[0] == values[2]:
			break
		elif values[0] > values[2]:
			i += 1
			break
		values[0] += 2
		i += 1

	print(i)

if __name__ == '__main__':
	values = list(map(int, input().split()))
	main(values)

Measured memory_bytes: 3064
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();

		int ans = 0;
		int kt = 1;

		if (B == 1) {
			System.out.println(0);
			return;
		}

		while(kt < B) {
			ans++;
			kt -= 1;
			kt += A;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 25044
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int n = sc.nextInt();
		boolean flag = false;
		int count = 0; int sum = 0;

		for(int i = 0; i < n; i++) {
			if(sc.nextInt() == i+1) {
				flag = true;
				count++;
			}else if(flag){
				list.add(count);
				flag = false;
				count = 0;
			}
		}

		if(flag) list.add(count);

		for(int chain : list) {
			double c = chain;
			sum += Math.ceil(c/2);
		}

		System.out.println(sum);

		sc.close();
	}
}

Measured memory_bytes: 48008
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


int seen[100005]={};
int pn[100005]={};

int cn[100005]={};

int n,m;
int main(void){
	scanf("%d%d",&n,&m);
	rep(i,n){
		int a;
		scanf("%d",&a);
		int mo = a%m;
		cn[mo]++;
		if(seen[a])pn[mo]++;
		seen[a] = 1-seen[a];
	}
	
	int ans=0;
	ans += cn[0]/2;
	
	reg(i,1,(m-1)/2){
		int np=min(cn[i],cn[m-i]);
		cn[i] -= np;
		cn[m-i] -= np;
		ans += np;
		//printf("%d\n",np);
		ans += min(cn[i]/2,pn[i]);
		ans += min(cn[m-i]/2,pn[m-i]);
	}
	//printf("a .. %d\n",ans);
	if(m%2==0){
		ans += cn[m/2]/2;
	}
	printf("%d\n",ans);
		
	return 0;
}






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

int a[2001];
int dp[2001][2];

int N;

int calc(int p, int turn) {
	if (p == N - 1) return abs(a[p + 1] - a[p]);
	if (dp[p][turn] >= 0) return dp[p][turn];
	int res = abs(a[N] - a[p]);
	for (int i = p + 1; i < N; i++) {
		res = turn ? min(res, calc(i, !turn)) : max(res, calc(i, !turn));
	}
	return dp[p][turn] = res;
}

int main()
{
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < 2; j++) {
			dp[i][j] = -1;
		}
	}
	int Z;
	cin >> N >> Z >> a[0];
	for (int i = 0; i < N; i++) {
		cin >> a[i + 1];
	}
	cout << calc(0, 0) << endl;
	return 0;
}


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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 1e5 + 5;

ll root, ans = 1, n, k;
vector < ll > fact(MAXN);
vector < vector < ll > > adj(MAXN, vector < ll > ());

ll pwr(ll a, ll b){
  ll res = 1;
  while(b > 0){
    if(b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

ll inv(ll a){
  return pwr(a, mod - 2);
}

ll comb(ll n, ll r){
  if(r > n){
    cout << 0 << endl;
    exit(0);
  }
  return (((fact[n] * inv(fact[r])) % mod) * inv(fact[n - r])) % mod;
}

void dfs(ll u, ll p){
  if(u == root){
    ans = (ans * ((fact[adj[u].size() + 1] * comb(k, adj[u].size() + 1)) % mod)) % mod;
  }else{
    ans = (ans * ((fact[adj[u].size() - 1] * comb(k - 2, adj[u].size() - 1)) % mod)) % mod;
  }
  for(auto to : adj[u]){
    if(to != p){
      dfs(to, u);
    }
  }
}

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

  fact[0] = 1;
  for(int i = 1; i < MAXN; i++) fact[i] = (i * fact[i - 1]) % mod;

  cin >> n >> k;
  for(int i = 0; i < n - 1; i++){
    ll u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  if(n == 1){
    cout << k << endl;
    return 0;
  }
  if(n == 2){
    cout << (k * (k - 1)) % mod << endl;
    return 0;
  }

  for(int i = 1; i <= n; i++){
    if(adj[i].size() != 1){
      root = i; break;
    }
  }

  dfs(root, -1);

  cout << ans << '\n';
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = 3.141592653589793;

class UnionFind{
    private:
        vector<ll> parent,rank,tree_w;
    public:
        UnionFind(int size){
            for (int i=0; i<size; i++){
                parent.push_back(i);
                rank.push_back(0);
                tree_w.push_back(1);
            }
        }

        int findset(int x){
            return x==parent[x] ? x : parent[x]=findset(parent[x]);
        }

        void unite(int x,int y){
            x=findset(x);y=findset(y);
            if (x==y) return;
            if (rank[x]>rank[y]) swap(x,y);
            parent[x]=y;
            tree_w[y]+=tree_w[x];
            if (rank[x]==rank[y]) rank[y]+=1;
        }

        ll tree_weight(int x){
            return tree_w[findset(x)];
        }
};

ll n;
ll a[200000+5];
ll pos[200000+5];
bool check[200000+5];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    rep(i,n) pos[a[i]]=i;
    UnionFind uf(n);
    ll ans=0LL;
    rrep(i,n-1){
        ll l=max<ll>(pos[i]-1,0);
        ll r=min<ll>(pos[i]+1,n-1);
        ll lnum=1LL;
        ll rnum=1LL;
        if (check[l]){
            lnum+=uf.tree_weight(l);
        }
        if (check[r]){
            rnum+=uf.tree_weight(r);
        }
        if (check[l]){
            uf.unite(l,pos[i]);
        }
        if (check[r]){
            uf.unite(r,pos[i]);
        }
        check[pos[i]]=true;
        ans+=(i+1)*lnum*rnum;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int n;

	cin >> n;

	while (n > 0) {
		for (int i = 0; i < n; i++) {
			int a[4], b[4], c[4];
			cin >> a[0] >> a[1] >> a[2] >> a[3]
				>> b[0] >> b[1] >> b[2] >> b[3];

			c[0] = a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3];
			c[1] = a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2];
			c[2] = a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1];
			c[3] = a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0];

			for (int i = 0; i < 3; i++)
				cout << c[i] << " ";
			cout << c[3] << endl;
		}

		cin >> n;
	}
	
	return 0;
}


Measured memory_bytes: 3104
abcd= list(map(int,input().split()))
a=abcd[0]
b=abcd[1]
c=abcd[2]
d=abcd[3]
n=[]
n.append(a*c)
n.append(a*d)
n.append(b*c)
n.append(b*d)
print(max(n))

Measured memory_bytes: 9188
import java.util.Scanner;

public final class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();

        if(0<=a && a<=5){
            System.out.println(0);
        }else if(13<=a){
            System.out.println(b);
        }else{
            System.out.println(b/2);
        }
    }
}

Measured memory_bytes: 21844
L, R = map(int, input().split())

res = 10 ** 9
flag = False

for i in range(L, R+1):
    for j in range(L, R+1):
        if i%2019 == 0 or j%2019 == 0:
            res = 0
            flag = True
            break

        if i != j:

            res = min(res, i*j%2019)

    if flag:
        break

print(res)


Measured memory_bytes: 40556
import java.util.Scanner;

public class Main {

	static int h, w, n, a[];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		h = sc.nextInt();
		w = sc.nextInt();
		n = sc.nextInt();
		a = new int[n];
		for (int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		sc.close();

		int ans[][];
		ans = new int[h][w];
		int key = 0, max;

		for (int i = 0; i < h; ++i) {
			max = a[key];
			for (int j = 0; j < w; ++j) {
				if (i % 2 == 0) {
					if (max > j) {
						ans[i][j] = key + 1;
						a[key]--;
					} else {
						++key;
						max = a[key] + j;
						ans[i][j] = key + 1;
						a[key]--;
					}
				} else {
					if (max > j) {
						ans[i][w - j - 1] = key + 1;
						a[key]--;
					} else {
						++key;
						max = a[key] + j;
						ans[i][w - j - 1] = key + 1;
						a[key]--;
					}
				}
			}
		}

		for (int i = 0; i < h; ++i) {
			for (int j : ans[i])
				System.out.print(j + " ");
			System.out.println();
		}
	}

}


Measured memory_bytes: 35388
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	int a[n+1],ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(i%2&&a[i]%2)
		++ans;
	}
	cout<<ans;		
	return 0;
}

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

int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0){
    cout<<1<<endl;
  }
    if(b==0){
    cout<<2<<endl;
  }  if(c==0){
    cout<<3<<endl;
  }  if(d==0){
    cout<<4<<endl;
  }  if(e==0){
    cout<<5<<endl;
  }
}

Measured memory_bytes: 3636
import java.io.PrintWriter;
import java.util.Scanner;


public class Main {

	static final int INF = Integer.MAX_VALUE/2;

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		while(true){
			int n = Integer.parseInt(scan.next());
			if(n==0) break;
			int[][] d = new int[10][10];
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					d[i][j] = INF;
					if(i==j) d[i][j] = 0;
				}
			}
			int m = 0;
			for (int i = 0; i < n; i++) {
				int a = Integer.parseInt(scan.next()),b = Integer.parseInt(scan.next()),c = Integer.parseInt(scan.next());
				d[b][a] = d[a][b] = c;
				m = (short)Math.max(Math.max(a, b),m);
			}
			m++;

			for (int k = 0; k < m; k++) {
				for (int i = 0; i < m; i++) {
					for (int j = 0; j < m; j++) {
						d[i][j] = Math.min(d[i][j], d[i][k]+d[k][j]);
					}
				}
			}

			int mincost=INF,v=0;
			for (short i = 0; i < m; i++) {
				int sum = 0;
				for (short j = 0; j < m; j++) {
					sum+=d[i][j];
				}
				if(mincost>sum){
					mincost = sum;
					v = i;
				}
			}
			out.println(v+" "+mincost);
		}

		out.flush();
	}

}

Measured memory_bytes: 17996
#include <iostream>

int main(){
  char c[9];
  while(std::cin>>c){
    if(std::cin.eof())break;
    bool f=true;
    for(int i=0;i<3;i++){
      if(c[i*3]==c[i*3+1]&&c[i*3]==c[i*3+2])
	{if(c[i*3]!='s'){std::cout<<c[i*3]<<std::endl;f=false;break;}}
      if(c[i]==c[i+3]&&c[i]==c[i+6])
	{if(c[i]!='s'){std::cout<<c[i]<<std::endl;f=false;break;}}
    }
    if(c[0]==c[4]&&c[0]==c[8])
      {if(c[0]!='s'){std::cout<<c[0]<<std::endl;f=false;continue;}}
    if(c[2]==c[4]&&c[2]==c[6])
      {if(c[2]!='s'){std::cout<<c[2]<<std::endl;f=false;continue;}}
    if(f)std::cout<<'d'<<std::endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=100005;
const int mod=1e9+7;
inline int Add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
inline int Sub(int x,int y){
    return (x-=y)>=0?x:x+mod;
}
inline int Mul(int x,int y){
    return 1ll*x*y%mod;
}
int n,x[max_n];
int inv[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",x+i);
    inv[1]=1;
    for(int i=2;i<=n;i++)inv[i]=Mul(inv[mod%i],mod-mod/i);
    for(int i=1;i<=n;i++)inv[i]=Add(inv[i-1],inv[i]);
    int ans=0;
    for(int i=1;i<n;i++){
        int tmp=Sub(x[i+1],x[i]);
        tmp=Mul(tmp,inv[i]);
        ans=Add(ans,tmp);
    }
    for(int i=1;i<n;i++)ans=Mul(ans,i);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in(), c = in(), d = in();
	cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define p_b push_back
#define all(c)              c.begin(), c.end()
using namespace std;
typedef long long ll; //printf("%lld ", ll); to out put long
typedef pair <int , int> pii;
typedef pair <ll , ll> pll;
const double eps = 1e-6;
const int MAXN = 1e6 + 5;
const ll MOD = 1e9 + 7;
bool ODD(ll O) {return (O % 2 != 0);}
ll gcd(ll a, ll b) {return __gcd(a , b);}
int dx[] = {1, 0, -1 ,0 , -1 , 0};
int dy[] = {0, 1, 0, -1 , -1 , 0};
ll power (ll x, ll y) {
    if(y == 0) return 1;
    if(ODD(y)) return x * power(x , y / 2) * power(x , y / 2);
    return power(x , y / 2) * power(x , y / 2);
}
/*------ never give up --------*/
int fix(ll n) {
    return (n % 26);
}

int main () {
    int t = 1;
    //cin >> t;
    while(t--) {
        int n, x;
        cin >> x >> n;
        set<int> st;
        for(int i = 0; i <= 100 + 1; i++) st.insert(i);
        for(int i = 0; i < n; i++) {
            int a;
            cin >> a;
            st.erase(a);
        }
        auto it = st.lower_bound(x);
        auto iit = st.upper_bound(x);
        if(*it - x == 0) {
            return cout << x, 0;
        }
        --it;
        if(abs(x - *it) <= abs(x - *iit)) return cout << *it, 0;
        cout << *iit, 0;

    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
 
int main(){
    int A,B;
    cin>>A>>B;
    if(A+B>=24){
        cout<<A+B-24<<endl;
    }
    else{
        cout<<A+B<<endl;
    }
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N, A, B = map(int, input().split())

    if (B - A) % 2 == 0:
        ans = (B - A) // 2
    else:
        a = (A - 1) + 1 + ((B - ((A - 1) + 1)) - 1) // 2
        b = (N - B) + 1 + (N - (A + ((N - B) + 1))) // 2
        ans = min(a, b)

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

#define F first
#define S second

typedef pair<int, int> State;
int n;
vvi edge;

void bfs(int s, vi& dist){
    dist = vi(n, inf);
    dist[s] = 0;

    queue<int> q;
    q.push(s);

    while(!q.empty()){
        int v = q.front(); q.pop();

        for(int u : edge[v]){
            if(dist[u] != inf) continue;

            dist[u] = dist[v] + 1;
            q.push(u);
        }
    }
}

int main(void){
    ll res;
    for(int m, s, t; cin >> n >> m >> s >> t; cout << res << endl){
        res = 0;

        s--, t--;
        edge = vvi(n);

        rep(i, m){
            int x, y; cin >> x >> y;
            x--, y--;
            
            edge[x].pb(y), edge[y].pb(x);
        }

        vi dist_fromS, dist_fromT;
        bfs(s, dist_fromS);
        bfs(t, dist_fromT);

        map<int, ll> distCnt_fromS, distCnt_fromT;
        rep(u, n){
            distCnt_fromS[dist_fromS[u]]++;
            distCnt_fromT[dist_fromT[u]]++;
        }

        int path_len = dist_fromS[t];

        rep(i, path_len - 1){
            res += distCnt_fromS[i] * distCnt_fromT[path_len - i - 2];
        }
    }

	return 0;
}

Measured memory_bytes: 8368
import java.util.Scanner;
public class Main {
  static final long LLINF = 1100000000000000000l;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int Q = sc.nextInt();
    long[] s = new long[A + 2];
    for (int i = 1; i <= A; i++) {
      s[i] = sc.nextLong();
    }
    s[0] = -LLINF;
    s[A + 1] = LLINF;
    long[] t = new long[B + 2];
    for (int i = 1; i <= B; i++) {
      t[i] = sc.nextLong();
    }
    t[0] = -LLINF;
    t[B + 1] = LLINF;
    long[] x = new long[Q];
    for (int i = 0; i < Q; i++) {
      x[i] = sc.nextLong();
    }

    for (int q = 0; q < Q; q++) {
      long ans = LLINF;
      int sl = lower_bound(s, x[q]);
      int tl = lower_bound(t, x[q]);
      for (int i = sl; i <= sl + 1; i++) {
        for (int j = tl; j <= tl + 1; j++) {
          ans = Math.min(ans, Math.abs(s[i] - x[q]) + Math.abs(t[j] - s[i]));
          ans = Math.min(ans, Math.abs(t[j] - x[q]) + Math.abs(s[i] - t[j]));
        }
      }
      System.out.println(ans);
    }
  }
  static int lower_bound(long[] a, long x) {
    int lb = 0, ub = a.length;
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2;
      if (a[mid] <= x) lb = mid;
      else ub = mid;
    }
    return lb;
  }
}

Measured memory_bytes: 101868
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> gr[114514];
int f=0,ka=0;
int num[114514];
//vector<int> ok,ng;
void dfs(int v,int d){
	if(num[v]>=0){
		if(num[v]!=d) f=1;
		return;
	}
	//cout<<v<<' '<<d<<endl;
	num[v]=d;ka++;
	rep(i,gr[v].size()) dfs(gr[v][i],1-d);
}
int main()
{
	int n,m,a,b;lint one=0,ok=0,ng=0,N,out=0;
	cin>>n>>m;N=n;
	rep(i,m){
		cin>>a>>b;a--;b--;
		gr[b].pb(a);gr[a].pb(b);
	}
	memset(num,-1,sizeof(num));
	rep(i,n){
		//cout<<i<<endl;
		if(num[i]>=0) continue;
		f=0;ka=0;
		dfs(i,0);
		if(ka<2) one++;
		else if(f==0) ok++;
		else ng++;
	}
	out+=2*ok*ok;
	out+=ng*ng+2*ng*ok;
	out+=one*one+2*one*(N-one);
	cout<<out<<endl;
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n;
    cin >> n;
    bool check = true;
    for(int i=0;i<n;i++)
    {
        int t;
        cin >> t;
        if(t%2 == 0)
        {
            if(!(t%3 == 0 || t%5 == 0))
                check  = false;
        }
    }
    if(check) cout << "APPROVED\n";
    else cout << "DENIED\n";
    return 0;
}



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

int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D ;

    if((A-1)/D >= (C-1)/B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int a,b,c; cin >> a >> b >> c;
    Ans(a+b>=c);
    return 0;
}

Measured memory_bytes: 256
# snuke解説板
from heapq import heappush, heappop

infi = 10 ** 20
n, m, s = map(int, input().split())

s = min(s, n * 50)

edges = [[] for _ in range(n + 1)]
# edge:1-50, max silver=0-2500

for _ in range(m):  # a円, b分
    u, v, a, b = map(int, input().split())
    edges[v].append((u, a, b))
    edges[u].append((v, a, b))

exchange = [(0, 0)] * (n + 1)

for edge_num in range(1, n + 1):  # c円, d分
    c, d = map(int, input().split())
    exchange[edge_num] = (c, d)

start = 1
# dp[i][j], 頂点iにお金jを持って到達する最低時間→時間に関してDAG
dp = [[infi] * (n * 50 + 1) for _ in range(n + 1)]


def dijkstra(edges, start, s, dp):
    dp[start][s] = 0
    edgelist = []
    heappush(edgelist, (0, s, start))  # 時間, お金, 頂点
    while edgelist:
        nowtime, nowmoney, nowedge = heappop(edgelist)
        # 遷移させる条件はedge,moneyの組み合わせに対してその時の最小値が出てきたときのみ→最小値以外は飛ばす。
        if dp[nowedge][nowmoney] != nowtime:
            continue
        # 両替
        deltamoney, deltatime = exchange[nowedge]
        nextmoney = min(nowmoney + deltamoney, n * 50)
        nexttime = nowtime + deltatime
        if dp[nowedge][nextmoney] > nexttime:
            dp[nowedge][nextmoney] = nexttime
            heappush(edgelist, (nexttime, nextmoney, nowedge))
        # 移動
        for v, vmoney, vtime in edges[nowedge]:
            nexttime = nowtime + vtime
            nextmoney = nowmoney - vmoney
            if nextmoney < 0:
                continue
            if dp[v][nextmoney] > nexttime:
                dp[v][nextmoney] = nexttime
                heappush(edgelist, (nexttime, nextmoney, v))
    return dp


time = dijkstra(edges, start, s, dp)

ans = [infi] * (n + 1)
for i in range(1, n + 1):
    for j in range(n * 50 + 1):
        ans[i] = min(ans[i], dp[i][j])

print(*ans[2 : (n + 1)], sep="\n")


Measured memory_bytes: 93220
#include <iostream>

using namespace std;
long long cmmdc(int a, int b)
{
    int r;
    r=a%b;
    while(r!=0)
    {
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main()
{
    long long sum=0, n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
           long long k2 = cmmdc(i,j);
           for(int k=1; k<=n; k++)
           {
                sum=sum + cmmdc(k2,k);
           }
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3624
p,q= input().split()
a,b =(int(p), int(q))
ans =''
num_list =[]
pare_list=[]
for i in range(b):
    c = map(int,input().split())
    pare_list.append(list(c))
    num_list.append(pare_list[i][0])

search_list = list(range(a*10**3))[10**(a-1):10**(a)]


ans_list=[]
for i in search_list:
    count = 0
    ans_str = str(i)
    
    for j in range(b):
        
        if pare_list[j][1]==int(ans_str[num_list[j]-1]):
            count +=1
        else:
            break
        
        if count == len(num_list):
            ans_list.append(i)
            break

if len(ans_list)>=1:
    print(ans_list[0])
else:
    if a == 1 and b ==0:
        print(0)
    elif a== 1 and pare_list[0][1]==0:
        print(0)
    elif a>= 2 and b==0:
        print(10**(a-1))
    
    
    else:
        print(-1)

Measured memory_bytes: 3064
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};



int main(){
 
    ll n,d;
    cin >> n >> d;
    vector<pair<ll,ll>> a(n);
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        a[i].first = x;
        a[i].second = y;
    }
    ll ans = 0;
    rep(i,n){
        ll x = a[i].first;
        ll y = a[i].second;
        if(sqrt(x*x+y*y) <= d){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5988
#include <iostream>

using namespace std;

typedef long long ll;

int func(ll x) {
		if (x < 10) return 1;
		return func(x/10) + 1;
}

int main() {
		ll N;
		cin >> N;
		int ans = 1e9;

		for (ll i = 1; i*i <= N; i++) {
				ll j;
				if (N%i == 0) {
						j = N/i;
						ans = min(ans, func(j));
				}
		}

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


Measured memory_bytes: 256