akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
    class Class2
    {
        static void Main()
        {
            var I = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = I[0];
            int N = I[1];
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(H - A.Sum() <= 0 ? "Yes" : "No");

        }
    }
}


Measured memory_bytes: 19680
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define sz(a) ll(a.size())
#define trace(c,x) for(auto &x:c)
#define F first
#define S second		
ll mod = 1e9 + 7;   //change acc to question

ll fastexpo(ll x,ll y)
{
	ll a=1;
	while(y>0)
	{
		if(y&1)a = (a*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}	
	return a;
}

ll weight[100005];
ll val[100005];
ll memo[105][100005];

ll dp(int i,int rem)
{
	if(rem<=0)
		return 0;
	if(i==0)
	{
		if(val[i] < rem)
			return 1e10;
		else
			return weight[i];
	}
	if(memo[i][rem]!=-1)
		return memo[i][rem];

	memo[i][rem] =  min(weight[i]+dp(i-1,rem-val[i]),dp(i-1,rem));	
	return memo[i][rem];
}

int main(){

ios::sync_with_stdio(false);

int n,w;
cin>>n>>w;
for(int i=0;i<n;i++)
{
	cin>>weight[i]>>val[i];
}
for(int i=0;i<n;i++)
{
	for(int j=0;j<=100004;j++)
		memo[i][j] = -1;
}
for(int i=0;i<=100000;i++)
	memo[n-1][i] = dp(n-1,i);

int ans = 0;
for(int i=0;i<=100000;i++)
{
	if(memo[n-1][i]>w)
		break;
	ans = i;
}	
cout<<ans<<endl;
return 0;

}	

Measured memory_bytes: 80128
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t N, K, Q;
  cin >> N >> K >> Q;
  vector<int32_t> A(Q);
  vector<int32_t> scores(N, K-Q);
  for (int32_t i = 0; i < Q; ++i) {
    int32_t a;
    cin >> a;
    const int32_t person_index = a - 1;
    scores[person_index]++;
  }
  for (int32_t j = 0; j < N; ++j) {
    if (scores[j] > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1408
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll t0,t1,a0,a1,b0,b1;
  ll cnt=0;
  ll p1,p0,diff;
  cin >> t0 >> t1 >> a0 >> a1 >> b0 >> b1;
  p0 = t0*(a0-b0);
  p1 = p0 + t1*(a1-b1);
  if(p1==0){
    cout << "infinity"<<endl;
    return 0;
  }
  if((p0>0&&p1>0)||(p0<0&&p1<0)){
    cout << 0 << endl;
    return 0;
  }
  if(p1<0){
    p0 *= -1;
    p1 *= -1;
  } 
  cnt++;
  cnt += (-p0 / p1)*2;
  if((-p0)%p1 == 0) cnt--;
  cout << cnt << endl;
}


Measured memory_bytes: 3588
import java.util.*;

public class Main {
  static long[] f;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long x = sc.nextLong();
    f = new long[n + 1];
    f[0] = 1;
    for(int i = 1; i <= n; i++) {
      f[i] = 2 * f[i - 1] + 3;
    }
    System.out.println(func(n, x));
  }

  public static long func(int m, long y) {
    if(m == 0) {
      if(y == 0) return 0;
      return 1;
    } else {
      if(y == 0) {
        return 0;
      } else if(y <= (1 + f[m - 1])) {
        return func(m - 1, y - 1);
      } else if(y == (2 + f[m - 1])) {
        return func(m - 1, f[m - 1]) + 1;
      } else if(y < f[m]) {
        return func(m - 1, f[m - 1]) + 1 + func(m - 1, y - 2 - f[m - 1]);
      } else {
        return (2 * func(m - 1, f[m - 1]) + 1); 
      }      
    }
  }
}

Measured memory_bytes: 23764
n = int(input())
s, h, c, d = {}, {}, {}, {}

i = 1
while i <= 13:
    s[i], h[i], c[i], d[i] = 0, 0, 0, 0
    i += 1

i = 0
while n != i:
    card = input().split()
    if card[0] == "S":
        s[int(card[1])] = int(card[1])
    elif card[0] == "H":
        h[int(card[1])] = int(card[1])
    elif card[0] == "C":
        c[int(card[1])] = int(card[1])
    elif card[0] == "D":
        d[int(card[1])] = int(card[1])
    i += 1

i = 1
while i <= 13:
    if i != s[i]:
        print("S {}".format(i))
    i += 1
i = 1
while i <= 13:
    if i != h[i]:
        print("H {}".format(i))
    i += 1
i = 1
while i <= 13:
    if i != c[i]:
        print("C {}".format(i))
    i += 1
i = 1
while i <= 13:
    if i != d[i]:
        print("D {}".format(i))
    i += 1



Measured memory_bytes: 5612
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>
 
const int N=805;
int h,w,k;
char grid[N][N];
bool vis[N][N];
 
int foo(int x,int y) {
    if (x==0||x==h-1||y==0||y==w-1) return 0;
    int res=INF;
 
    int tmp=(x-1)/k+1;
    res=min(res,tmp);
 
    int xx=h-1-x;
    tmp=(xx-1)/k+1;
    res=min(res,tmp);
 
    tmp=(y-1)/k+1;
    res=min(res,tmp);
 
    int yy=w-1-y;
    tmp=(yy-1)/k+1;
    res=min(res,tmp);
 
    return res;
}
 
int ans=INF;
 
struct node {
    int x,y,dis;
};
 
void bfs(int x,int y) {
    queue<node> q;
    q.push({x,y,0});
    vis[x][y]=1;
    ans=min(ans,foo(x,y)+1);
    while (!q.empty()) {
        node cur=q.front();
        q.pop();
        for (int i=-1;i<=1;i++) {
            for (int j=-1;j<=1;j++) {
                if ((i==0&&j==0)||(i!=0&&j!=0)) continue;
                int xx=cur.x+i;
                int yy=cur.y+j;
                if (xx>=0&&xx<h&&yy>=0&&yy<w&&!vis[xx][yy]&&grid[xx][yy]!='#') {
                    ans=min(ans,foo(xx,yy)+1);
                    vis[xx][yy]=1;
                    if (cur.dis+1<k) q.push({xx,yy,cur.dis+1});
                }
            }
        }
    }
}
 
int main() {
    scanf("%d%d%d",&h,&w,&k);
    for (int i=0;i<h;i++) {
        scanf("%s",grid[i]);
    }
    int sx,sy;
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            if (grid[i][j]=='S') {
                sx=i;
                sy=j;
                break;
            }
        }
    }
    bfs(sx,sy);
    printf("%d\n",ans);
}


Measured memory_bytes: 1536
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

a, b, c = MAP()
 
if Decimal(a)**Decimal("0.5") + Decimal(b)**Decimal("0.5") < Decimal(c)**Decimal("0.5"):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 5392
import math
while 1:
    student_num = int(input())
    if student_num == 0:
        break
    student_scores = list(map(int,input().split()))
    avg = sum(student_scores)/ student_num
    
    a = 0
    
    for i in range(student_num):
        a += (student_scores[i] - avg) ** 2
    
    a = a / student_num
    
    print(math.sqrt(a))


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

int digit(int C, int d);
int f(int C);

int A, B, j=0;

int main() {
  cin >> A >> B;
  for (; A<B+1; A++){
    j += f(A);
  }
  cout << j << endl;
}

int digit(int C, int d){
  int x=0, y=1;
  for(int i=0; i<d; i++){
    x = (C%(y*10) -x)/y;
    y *= 10;
  }
  return x;
}

int f(int C){
  bool i;
  if(digit(C, 1) == digit(C, 5) && digit(C, 2) == digit(C, 4)){
    i = 1;
  } else {
    i = 0;
  }
  return i;
}

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

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] || s[1] == s[2]  || s[2] == s[3] ){
        cout << "Bad" << "\n";
    }else{
        cout << "Good" << "\n";
    }

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main (void){
    int n, m;
    cin >> n >> m;
    int rmin = 1;
    int rmax = n;
    for( int i = 1; i <= m; i++ ){
        int l, r;
        cin >> l >> r;
        if( r < rmax ) {
            rmax = r;
        } 
        if( rmin < l ){
            rmin = l;
        }
    }
    if(rmax-rmin+1 > 0 ){
        cout << (rmax-rmin+1) << endl;
    }
    else{
        cout << 0 << endl;
    }
}


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

long long int mergecount(vector<int> &a) {
  long long int count = 0;
  int n = a.size();
  if (n > 1) {
    vector<int> b(a.begin(), a.begin() + n/2);
    vector<int> c(a.begin() + n/2, a.end());
    count += mergecount(b);
    count += mergecount(c);
    for (int i = 0, j = 0, k = 0; i < n; ++i)
      if (k == c.size())       a[i] = b[j++];
      else if (j == b.size())  a[i] = c[k++];
      else if (b[j] <= c[k])   a[i] = b[j++];
      else                   { a[i] = c[k++]; count += n/2 - j; }
  }
  return count;
}

int main() {
	int n, t;
	vector<int> a;
	
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> t;
		a.push_back(t);
	}
	
	cout << mergecount(a) << endl;
	
	return 0;
}

Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define LONGMAX 1e18
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define INF 1e9
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){ll mid=(low+high)/2;if(low>high)return;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
int main()
{
	fastio();
	ll N,M,K;
	cin>>N>>M>>K;
	ll ar[N];
	for(ll i=0;i<M;i++)
	{
	    ar[i]=K;
	}
	ll f;
	if(K==1)
	    f=2;
	else
	    f=K-1;
	for(ll i=M;i<N;i++)
	{
	    ar[i]=f;
	}
	oa(ar,N);
}

Measured memory_bytes: 2176
/*
* Author: Anmol Choudhary
*/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int ll
const ll mod = 998244353;
const ll maxn = 200005;
const ll mm = 1e+18;
void solve()
{
    ll n,m;
    cin>>n>>m;
    ll an=n*(n-1)/2;
    an+=m*(m-1)/2;
    pr(an);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define INF 1145141919810364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, s;
int dp[3010][3010];
int ans;

signed main() {
	cin >> n >> s;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		int a;
		cin >> a;
		for (int j = 0; j <= s; j++) {
			dp[i][j] += dp[i - 1][j];
			if (j - a >= 0) {
				if (j - a == 0)dp[i][j] += dp[i - 1][j - a] * i;
				else dp[i][j] += dp[i - 1][j - a];
			}
			dp[i][j] %= mod;
		}
	}
	for (int i = 1; i <= n; i++) {
		ans += (dp[i][s] - dp[i - 1][s] + mod) * (n - i + 1);
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 70784
from collections import deque
N = int(input())
S = list(input() for i in range(N))
ans = -1
for i in range(N):
    queue = deque([i])
    V = [0]*N
    V[i] = 1
    while queue:
        q = queue.popleft()
        m = V[q]
        for i in range(N):
            if S[q][i] == "1":
                if V[i] == 0:
                    V[i] = m+1
                    queue.append(i)
                elif abs(V[i]-m) != 1:
                    print(-1)
                    exit()
    ans = max(max(V),ans)
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include<unordered_map>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int n;
	cin >> n;
	int count4 = 0;
	int count2 = 0;
	int count = 0;
	rep(i, n) {
		int a;
		cin >> a;
		if (a % 4 == 0) {
			count4++;
		}
		else if (a % 2 == 0) {
			count2++;
		}
		else {
			count++;
		}
	}
	bool flag = true;
	count4++;
	if (count2 > 0) {
		if (count < count4) {
			count++;
		}
		else {
			flag = false;
		}
	}
	if (count > count4) {
		flag = false;
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int>c(n);
    vector<vector<int>>a(n,vector<int>(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m)cin >> a[i][j];
    }
    int ans = 100000000;

    for(int i = 0;i < 1<<n;i++){
        vector<int>r(m);
        int price = 0;
        rep(j,n){
            if(i>>j & 1){
                rep(k,m)r[k] += a[j][k];
                price += c[j];
            }
        }
        bool ok = true;
        rep(j,m){
            if(r[j]<x)ok = false;
        }
        if(ok)ans = min(ans,price);
    }
    if(ans == 100000000){
        cout << -1 << endl;
    }else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
// Foods Loved by Everyone

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int n, m;

int main() {
    cin >> n >> m;
    vector<int> a(m, 0);
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        int tmp;
        for (int j = 0; j < k; j++) {
            cin >> tmp;
            a[tmp-1]++;
        }
    }

    int count = 0;
    for (int i = 0; i < m; i++) {
        if (a[i] == n) {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace attocoda
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
                Console.WriteLine("Possible");
            else
                Console.WriteLine("Impossible");
            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

ll modpow(ll x, ll n, int mod){
    if (n == 0){
        return 1;
    }
    ll half = modpow(x, n/2, mod);
    ll res = (half * half) % mod;
    if (n&1) res = (res * x) % mod;
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<ll> d(n);
    int mx = 0;
    rep(i,n){
        int x;
        cin >> x;
        if (i == 0 && x != 0){
            cout << 0 << endl;
            return 0;
        }
        d[x]++;
        mx = max(mx, x);
    }
    if (n > 1 && d[0] > 1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    const int mod = 998244353;
    for(int i = 1; i <= mx; i++){
        ans *= modpow(d[i-1], d[i], mod);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

vector<vector<P> > G(600, vector<P>(0));

ll NG;
vec NGs(0);
bool make_NG = true;
vector<long double> memo(600,INF);
bool stop = false;
long double dfs(ll v){
    if(v == N - 1) return 0;
    if(memo[v] != INF) return memo[v];
    long double res = 0, maxi = -1;
    ll sz = G[v].size(), max_index;
    for(P p : G[v]){
        if(p.se != NG) {
            long double temp = dfs(p.fi);
            res += temp;
            if(temp > maxi && make_NG) maxi = temp, max_index = p.se;
        }else {
            --sz;
        }
    }
    res = (res / sz) + 1;
    memo[v] = res;
    if(make_NG && sz != 1) NGs.push_back(max_index);
    return res;
}

int main() {
    cin>>N>>M;
    rep(i,M){
        cin>>A>>B;
        --A;
        --B;
        G[A].emplace_back(B, i);
    }
    NG = -1;
    long double ans = dfs(0);
    make_NG = false;
    rep(j,N) memo[j] = INF;
    for(ll ng : NGs) {
        NG = ng;
        ans = min(ans, dfs(0));
        rep(j,N) memo[j] = INF;
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n+2),b(n+2);
	FOR(i,1,n+1){
		cin>>a[i];
	}
	bool flag=true;
	priority_queue<P> que;
	FOR(i,1,n+1){
		cin>>b[i];
		if(b[i]<a[i]){
			flag=false;
		}
		if(b[i]!=a[i]) que.push(P(b[i],i));
	}
	if(!flag){
		cout<<-1<<endl;
		return 0;
	}
	b[0]=b[n],b[n+1]=b[1];
	ll ans=0;
	while(!que.empty()){
		auto [num,ind]=que.top();
		que.pop();
		ll diff=b[ind-1]+b[ind+1];
		if(b[ind]<=diff){
			cout<<-1<<endl;
			return 0;
		}
		if((b[ind]-a[ind])%diff){
			ll q=b[ind]/diff,r=b[ind]%diff;
			if(r<a[ind]){
				ll x=(a[ind]-r+diff-1)/diff;
				if((a[ind]-r)%diff==0) x++;
				q-=x;
				r+=x*diff;
			}
			ans+=q;
			b[ind]=r;
			que.push(P(b[ind],ind));
		}else{
			ans+=(b[ind]-a[ind])/diff;
			b[ind]=a[ind];
		}
		b[0]=b[n],b[n+1]=b[1];
	}
	cout<<ans<<endl;
}

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

int main()
{
	//平均点

	int P[5];
	int sum=0;
	for (int i = 0; i < 5; i++) {
		cin >> P[i];
		if (P[i] < 40) P[i] = 40;
		sum += P[i];
	}
	cout << sum / 5 << endl;
	//投票
	/*
	int N, M;
	cin >> N >> M;
	int A[1000], vote[1000];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		vote[i] = 0;
	}
	int b;
	for (int i = 0; i < M; i++) {
		cin >> b;
		for (int j = 0; j < N; j++) {
			if (A[j] <= b) {
				vote[j]++;
				break;
			}
		}
	}
	int temps = 0, ans;
	for (int i = 0; i < N; i++) {
		if (vote[i] > temps) {
			temps = vote[i];
			ans = i;
		}
	}
	cout << ans + 1 << endl;
	*/

	//2.すごろく	
	/*
	int n;
	cin >> n;
	int A, _A = 1;
	int k = 0;
	int A_count[100];
	A_count[0] = 1;
	for (int i = 0; i < n; i++)
	{
	cin >> A;
	if (A == 1)
	{
	if (A == _A)
	{
	A_count[k]++;
	}
	else
	{
	k++;
	A_count[k] = 2;
	}
	}
	_A = A;
	}
	sort(A_count, A_count + k + 1);
	cout << A_count[k] << endl;
	*/

	//タイムカード
	/*
	int t[2][3];
	int x[3][3];
	for (int n=0; n < 3; n++)
	{
	for (int i=0; i < 2; i++)
	for (int k=0; k < 3; k++)
	cin >> t[i][k];

	for (int m = 2; m >= 0; m--)
	{
	x[n][m] = t[1][m] - t[0][m];
	if (t[0][m] > t[1][m])
	{
	x[n][m] += 60;
	t[1][m - 1]--;
	}
	}
	}
	for (int n= 0; n < 3; n++)
	{
	cout << x[n][0] << ' ' << x[n][1] <<' '<< x[n][2] << endl;
	}
	*/



	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
using namespace std;
vector <int> edges[200000];
bool done[200000];

const long long MOD = 1000000007;
long long two_inverse_power[200001];
long long ans;

long long power(long long m, long long n){
    long long res = 1;
    while(n > 0){
        if(n & 1) {
            res = (res * m) % MOD;
        }
        m = (m * m) % MOD;
        n >>= 1;
    }
    return res;
}
long long inverse(long long a){
    return power(a, MOD - 2);
}

int dfs(int cur, int N){
    done[cur] = true;
    long long ret = 0;
    vector <int> child_node_nums;
    for(int i = 0; i < edges[cur].size(); i++){
        if(done[edges[cur][i]]){
            continue;
        }
        int tmp = dfs(edges[cur][i], N);
        ret += tmp;
        child_node_nums.push_back(tmp);
    }
    child_node_nums.push_back(N - ret - 1);

    long long not_hole = two_inverse_power[1];
    for(int i = 0; i < child_node_nums.size(); i++){
        long long tmp_not_hole = (two_inverse_power[N - child_node_nums[i]] - two_inverse_power[N] + MOD) % MOD;
        not_hole = (not_hole + tmp_not_hole) % MOD;
    }
    not_hole = (not_hole + two_inverse_power[N]) % MOD;
    ans = (ans + (1 - not_hole + MOD) % MOD) % MOD;
    return ret + 1;
}

int main(void){
    int N;
    cin >> N;
    for(int i = 0; i < N - 1; i++){
        int A;
        int B;
        cin >> A >> B;
        edges[A - 1].push_back(B - 1);
        edges[B - 1].push_back(A - 1);
    }

    two_inverse_power[0] = 1;
    long long two_inverse = inverse(2);
    for(int i = 1; i <= N; i++){
        two_inverse_power[i] = (two_inverse * two_inverse_power[i - 1]) % MOD;
    }

    dfs(0, N);
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n; cin>>n;
	vector<int>h(n);
	vector<int>pos(n);
	vector<bool>one(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int ans=0;
	int active=0;
	for(int i=0;i<n;i++){
		if(active>=h[i]){
			active=h[i];
		}else{
			ans+=h[i]-active;
			active=h[i];
		}
	}
	cout<<ans<<endl;
}

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

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

using namespace std;

using int64 = int64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64 n;
  cin >> n;
  int ans;
  for (int64 i = 1; i * i <= n; i++) {
    if (i * (n / i) == n) {
      ans = (int)to_string(n / i).size();
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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(){
    int H,W,K;
    cin >> H >> W >> K;
    vector<string> A(H);
    rep(i,H) cin >> A[i];
    int sh,sw;
    rep(i,H) rep(j,W) if (A[i][j]=='S') sh=i,sw=j;
    int dh[4]={1,0,-1,0};
    int dw[4]={0,1,0,-1};
    queue<Pii> que;
    que.push(Pii(sh,sw));
    vector<vector<int>> d(H,vector<int>(W,-1));
    d[sh][sw]=0;
    int ans=INF;
    while(!que.empty()){
        Pii p=que.front();
        que.pop();
        int h=p.first,w=p.second;
        int x=(d[h][w]+min(h,min(H-1-h,min(w,W-1-w)))+K-1)/K;
        if (d[h][w]<K) x=1+(min(h,min(H-1-h,min(w,W-1-w)))+K-1)/K;
        chmin(ans,x);
        rep(j,4){
            int nh=h+dh[j],nw=w+dw[j];
            if (nh<0||nh>=H||nw<0||nw>=W) continue;
            if (A[nh][nw]=='#') continue;
            if (d[nh][nw]!=-1) continue;
            d[nh][nw]=d[h][w]+1;
            que.push(Pii(nh,nw));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;

int main()
{
    long long N;
    long long i;
    cin >> N;
    long long ans;
    long long tpm, npm, epm;
    tpm = 1;
    npm = 2;
    epm = 1;
    ans = 0;
    for (int i = 0; i < N; i++)
    {
        tpm = (tpm * 10) % mod;
    }
    for (int i = 0; i < N; i++)
    {
        npm = (npm * 9) % mod;
    }
    for (int i = 0; i < N; i++)
    {
        epm = (epm * 8) % mod;
    }
    ans = (tpm - npm + epm + mod) % mod;
    cout << ans << endl;
    return (0);
}


Measured memory_bytes: 3644
N,M = map(int,input().split())
if N == 1 and M == 1:
    print(1)
elif N == 2 or M == 2:
    print(0)
elif N == 1:
    print(M-2)
elif M == 1:
    print(N-2)
else:
    print((N-2) * (M-2))


Measured memory_bytes: 2940
#include <cstdio>

int main(void){
    int a, b, c, count = 0;
    scanf("%d %d %d", &a, &b, &c);
    for (int i = a; i <= b; i++) {
        if (c % i == 0) count++;
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#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 Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    string s;
    cin >> s;
    string ans = "";
    int n = s.size();
    int b = 0;
    rrep(i,n){
        if(s[i]=='B'){
            b++;
            continue;
        } 
        if(b){
            b--;
            continue;
        }
        ans = s[i]+ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int a[100001];
int com[100001],x[100001],y[100001],b[100001];
int B=1000;
int n,q;
void put(int a[100001]);
int min(int a,int b);
void update(int i,int x);
void find(int s,int t);
int main(void){
  put(a);
  int i;
  scanf("%d %d",&n,&q);
  for(i=0;i<q;i++){
    scanf("%d %d %d",&com[i],&x[i],&y[i]);
    if(com[i]==0)
      update(x[i],y[i]);
    else if(com[i]==1)
      find(x[i],y[i]);
  }
  return 0;
}
int min(int a,int b){
  if(a<=b)
    return a;
  else
    return b;
}
void update(int i,int x){
  int j;
  a[i]=x;
  b[i/B]=2147483647;
  for(j=i-i%B;j<min(i-i%B+B,n);j++){
    b[i/B]=min(b[i/B],a[j]);
  }
}
void find(int s,int t){
  int ans=2147483647;
  int j;
  for(j=s;j<=t;){
    if(j%B==0 && j+B<=t-1){
      ans=min(ans,b[j/B]);
      j+=B;
    }else{
      ans=min(ans,a[j]);
      j++;
    }
  }
  printf("%d\n",ans);
}
void put(int a[100001]){
  int i;
  for(i=0;i<100001;i++)
    a[i]=2147483647,b[i]=2147483647;
}

Measured memory_bytes: 2552
#include <iostream>
#include <string.h>
using namespace std;
int main(void){

    string s, p;
    cin >> s >> p;
    s += s;

    string::size_type result = s.find(p);

    if (result != string::npos) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3124
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	int n; cin >> n;
	V v(n); input(v);
	int ans = 1 << 29;
	rep(i, -100, 101) {
		int tmp = 0;
		for (int x : v)
			tmp += pow((x - i), 2);
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	system("pause");
}

Measured memory_bytes: 504
#include <iostream>
    #include <vector>
    #include <bits/stdc++.h>
    #define rep(i, n) for (int i = 0; i < (n); ++i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
     
    #define pb push_back
    #define eb emplace_back
    #define fi first
    #define se second
    #define bg begin()
    #define ed end()
    #define all(x) x.bg, x.ed
    #ifdef LOCAL
    #define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl
    #else
    #define dmp(x) void(0)
    #endif
     
    template <class t, class u>
    void chmax(t &a, u b)
    {
      if (a < b)
        a = b;
    }
    template <class t, class u>
    void chmin(t &a, u b)
    {
      if (b < a)
        a = b;
    }
     
    template <class t>
    using vc = vector<t>;
    template <class t>
    using vvc = vc<vc<t>>;
     
    using vi = vc<int>;
    int gcd(int a, int b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
    int lcm(int a, int b)
    {
      return (a * b) / gcd(a, b);
    }
    int fact(int n)
    {
      if (n == 0)
        return 1;
      return n * fact(n - 1);
    }
     
    int main()
    {
      int a,b;
      cin >> a >> b;
      if(a == 1)a=14;
      if(b == 1)b=14;
      if(a>b){
      cout << "Alice"<<endl;
      }else if(a ==b){
      cout << "Draw" <<endl;
      }else{
      cout << "Bob" <<endl;
      }
    }

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

#define LNUM 1000000007
#define llint long long int


int main(void){
  int h,w,k;
  std::cin >> h >> w >> k;

  std::vector<std::vector<int> > patterns;
  for(int i=0; i<std::pow(2, w-1); i++){
    if((i &      0b11) ==      0b11) continue;
    if((i &     0b110) ==     0b110) continue;
    if((i &    0b1100) ==    0b1100) continue;
    if((i &   0b11000) ==   0b11000) continue;
    if((i &  0b110000) ==  0b110000) continue;
    if((i & 0b1100000) == 0b1100000) continue;

    std::vector<int> temp;
    for(int j=0; j<w; j++){
      if     (i & (0b1 <<   j)) temp.push_back(j+1);
      else if(i & (0b1 <<   j-1)) temp.push_back(j-1);
      else temp.push_back(j);
    }
    patterns.push_back(temp);
  }

  llint dp[h+1][w];
  for(int i=0; i<h+1; i++){
    for(int j=0; j<w; j++){
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      for(auto pattern: patterns){
        dp[i+1][pattern[j]] = (dp[i+1][pattern[j]] + dp[i][j])%LNUM;

      }
    }
  }

  std::cout << dp[h][k-1] << std::endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{ll to,cost;};
#define MAX 2005
ll inf = 20000000;
ll INF = inf*3000LL;

int N,M,K;
vector<edge> G[MAX];

ll DP[MAX][MAX];
ll dp[MAX][MAX][2];
ll V[MAX];

bool visited[MAX];
vector<ll> A,B;

void calc(bool flg){
  int size=A.size();
  dp[0][1-flg][1-flg]=-INF;  
  dp[0][flg][flg]=0;
  for(int i=1;i<size;i++){
    for(int j=0;j<=size;j++){
      dp[i][j][0]=max(dp[i-1][j][1],dp[i-1][j][0]);
      V[j]=max(V[j],dp[i][j][0]);
      if(j==0)continue;
      ll cost=max(dp[i-1][j-1][0],dp[i-1][j-1][1]+B[i-1]);
      if(i+1==size&&A.size()==B.size()&&flg){
        cost+=B[i];
      }
      dp[i][j][1]=cost;
      V[j]=max(V[j],dp[i][j][1]);
    }
  }

}

void dfs(int pos,int prev){
  if(visited[pos])return;
  visited[pos]=true;
  A.push_back(pos);
  for(int i=0;i<(int)G[pos].size();i++){
    if(G[pos][i].to==prev)continue;
    B.push_back(G[pos][i].cost);
    dfs(G[pos][i].to,pos);
    break;
  }
}

int search(int p){
  map<int,bool> mp;
  while(!mp[p]){
    mp[p]=true;
    for(int i=0;i<(int)G[p].size();i++){
      edge e=G[p][i];
      if(!mp[e.to]){
        p=e.to;
        break;
      }
    }
  }
  return p;
}

int main(){
  cin>>N>>M>>K;
  for(int i=0;i<M;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    if(c==0)c=-INF;
    G[a].push_back((edge){b,c});
    G[b].push_back((edge){a,c});
  }
  
  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      DP[i][j]=dp[i][j][0]=dp[i][j][1]=-INF;
  
  DP[0][0]=0;

  int C=0;
  for(int i=1;i<=N;i++){
    if(visited[i])continue;
    A.clear();
    B.clear();
    dfs( search(i) ,0);
    int size=A.size();
    fill(V,V+MAX,-INF);
    V[0]=V[1]=0;
    calc(true);
    calc(false);
    C++; 
    for(int j=0;j<=K;j++)
      for(int k=0;k<=min(j,size);k++)
        DP[C][j]=max(DP[C][j],DP[C-1][j-k]+V[k]);
  }
 
  if(DP[C][K] < -inf) cout << "Impossible" << endl;
  else cout << DP[C][K] << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int n;
string s[100010];

signed main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

    sort(s, s+n);

    int cnt = 0;
    int ans = 0;
    for (int i=0;i<n;i++) {
        if (i != n-1 && s[i] == s[i+1]) cnt++;
        else  {
            if (cnt <= 1) ans += cnt;
            else ans += cnt*(cnt+1)/2;
            cnt = 0;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 7296
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
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>();
		
		for(int i=0;i<3;i++) {
			list.add(sc.nextInt());
		}
		
		Collections.sort(list,Comparator.reverseOrder());
		
		String num1=list.get(0).toString()+list.get(1).toString();
		System.out.println(Integer.valueOf(num1)+list.get(2).intValue());
		
		sc.close();
	}
}

Measured memory_bytes: 25172
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <set>
using namespace::std;


int main(){
	string S; cin >> S;
	int len = S.size();
	if(len > 25) {
		int is_used[26] ={};
		string temp = "";
		temp += S[0];
		int ii = 0;
		for(int i = 1; i < len; i++){
			if(S[i-1] > S[i]){
				temp += S[i];
			} else {
				temp = S[i];
				ii = i;
			}
		}
		if(ii == 0){
			cout << -1;
			return 0;
		} 
		char q='z';
		for(int i = ii; i < 26; i++){
			if(S[i] > S[ii-1] && S[i] < q) q = S[i];
		}
		// cout << ii;
		for(int i = 0; i < ii-1; i++){
			cout << S[i];
		} cout << q;
		return 0;
		
	}
	int is_used[26] = {};
	for(int i = 0; i < len; i++){
		is_used[ S[i] - 'a' ] = 1;
	}
	for(int i = 0; i < 26; i++){
		if(is_used[i] == 0){
			char temp = 'a';
			temp += i;
			cout << S <<  temp;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int h,w,n;
vp a;

int main(){
	cin>>h>>w>>n;
	a=vp(n);
	for(int i=0;i<n;i++) cin>>a[i].first>>a[i].second;
	sort(a.begin(),a.end());
	vp b;
	for(int i=0;i<n;i++){
		while(b.size()&&b.back().second<=a[i].second) b.pop_back();
		b.push_back(a[i]);
	}
	int res=min(b[0].second,b.back().first);
	for(int i=0;i<b.size()-1;i++) res=min(res,b[i].first+b[i+1].second);
	cout<<res<<endl;
}


Measured memory_bytes: 3976
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n;cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  int MIN=a[0],MAX=a[0];
  rep(i,n){
    MIN=min(MIN,a[i]);
    MAX=max(MAX,a[i]);
  }
  cout<<MAX-MIN<<endl;
}

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

using namespace std;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pi;

int main()
{
    lli n, k;
    cin >> n >> k;
    lli g = n%k;
    cout << min(g, k-g) << "\n";

    return 0;
}


Measured memory_bytes: 256
S = input()
m = 0
count = 0
for s in S:
    if s in "A":
        count+=1
    elif s in "C":
        count+=1
    elif s in "G":
        count+=1
    elif s in "T":
        count+=1
    else:
        count=0
    m=max(m,count)
print(m)

Measured memory_bytes: 38256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

for i in range(n):
    if a[i]%4==0:
        ddict[4] += 1
    elif a[i]%2==0:
        ddict[2] += 1
    else:
        ddict[1] += 1

if ddict[4]>=floor(n/2):
    print("Yes")
elif ddict[2]>=(n-ddict[4]*2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 91456
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int ans = b * 2;
        c -= b;
        if (c <= a) {
            ans += c;
        } else {
            ans += a + 1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
from collections import deque


def main():
  def check(mp):
    for i in range(n):
      for j in range(i, n):
        if mp[i][j] != mp[j][i]: return 0
    return 1
  n = int(input())
  mp = deque([deque(list(input())) for _ in range(n)])
  ans = 0
  for a in range(n):
    mp.rotate()
    ans += check(mp)
  print(ans * n)
  
main()

Measured memory_bytes: 48820
#include <iostream>
#include <math.h>

using namespace std;

int main() {
    long long int l, r;
    cin >> l >> r;

    long long int ans = 400000000000;

    for (long long int i = l; i <= min(r, l + 2020); i++) {
        for (long long int j = i + 1; j <= min(r, l + 2020); j++) {
            ans = min(ans, (i * j) % 2019);
        }
    }

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

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long K;
    std::cin >> K;

    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};
    cout << a[K - 1] << endl;

    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
ll P[10], Q[10],mk[10],mk2[10];
ll i, j, k;
ll dfs(ll ii,ll *Ar,ll *Ck,ll *mk,ll& ct){
    ll i;
    if(ii==N){
        ++ct;
        /*
        printf("\n%lld : ", ct);
        fornum(i,0,N){
            printf("%lld ", Ar[i]);
        }*/
        fornum(i,0,N){
            if(Ar[i]!=Ck[i]){
                return 0;
            }
        }
        return ct;
    }
    fornum(i,0,N){
        
        if(mk[i]!=0)
            continue;
       // printf("%lld:%lld ", ii, i);
        mk[i] =1;
        Ar[ii] = i + 1;
        ll ret = dfs(ii + 1, Ar, Ck, mk, ct);
        mk[i] = 0;
        if(ret){
            return ret;
        }
    }
    return 0;
}

int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &P[i]);
    }
    fornum(i,0,N){
        scanf("%lld", &Q[i]);
    }
    j = 0;
    ll a = dfs(0, mk, P,mk2, j);
    j = 0;
    ll b = dfs(0, mk, Q,mk2, j);
    //printf("%lld %lld\n", a, b);
    printf("%lld", abs(a - b));
    return 0;
}

Measured memory_bytes: 256