akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        int M = stdIn.nextInt();

        int[] A = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            A[i] = stdIn.nextInt();
            sum += A[i];
        }
        stdIn.close();

        int over = 0;
        for (int i = 0; i < N; i++) {
            if ((double)A[i] >= (double)sum / (4 * M)) {
                over++;
            }
        }

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

Measured memory_bytes: 35820
import java.util.Scanner;

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

        int a[] = new int[26];
        int i;
        
        while(sc.hasNext()){
            String x = sc.next();

            for(i = 0;i < x.length();i++){
                char c = x.charAt(i);
                if(c >= 'a' && c <= 'z'){
                    a[c - 97]++;
                }
                else if(c >= 'A' && c <= 'Z'){
                    a[c - 65]++;
                }
            }
        }

        for(i = 0;i < 26;i++){
            System.out.printf("%c : %d\n",(i + 97),a[i]);
        }

    }
}


Measured memory_bytes: 26436
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n, i; cin >> n >> i;
    cout << n-i+1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	Main(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			boolean[] a = new boolean[10000];
			for(int i = 0; i < 10000; i++){
				a[i] = false;
			}
			for(int i = 0; i < n; i++){
				int t = sc.nextInt();
				a[t] = true;
			}
			String[] str = new String[1000];
			int t = 0;
			for(int i = 0; i < 10000; i++){
				if(a[i]){
					int c = 0;
					String st = "";
					st += Integer.toString(i);
					i++;
					for(;i < 10000; i++){
						if(a[i]){
							c++;
						} else {
							break;
						}
					}
					if(c > 0){
						st += "-";
						st += Integer.toString(i-1);
					}
					str[t++] = st;
				}
			}
			
			System.out.print(str[0]);
			for(int i = 1; i < t; i++){
				System.out.print(" "+str[i]);
			}
			System.out.println();
		}
	}
	
	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
   
using namespace std;
typedef long long int ll;
  
int main()
{
	string s;
	cin>>s;
	int n=s.length();
	int w;
	cin>>w;
	string ans;
	for(int i=0; i<n; i+=w){
		ans+=s[i];
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
 
N = int(input())
A = np.array([input().split() for _ in range(N)], dtype=np.int64).reshape(N,N)

np.fill_diagonal(A, 10**9+1)

ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    d = np.min(A[i]+A[j])
    if d > A[i][j]:
      ans+=A[i][j]
    elif d < A[i][j]:
      print(-1)
      exit()

print(ans)

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

if N==2:
  print('1 2 2')
  exit()

for h in range(N//4 +1, min(3501, 3*N//4 +1)):
  for n in range((N*h)//(4*h-N), min(3501, (2*N*h)//(4*h-N))):
    x = 4*h*n - N*n - N*h
    y = N*h*n
    if x>0 and not y%x:
      print('{} {} {}'.format(h,n,y//x))
      exit()


Measured memory_bytes: 3064
import java.util.*;

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

        int[] x = new int[N];

        for(int i =0; N > i; i++){
            x[i] = sc.nextInt();     
        }
        int tmp = 0;
        int a =  0;

        for(int j = 0; N  > j; j++){  
            int b = Math.abs(X - x[j]);
            if(a == 0){
                a = b;
            }else{
                while ((tmp = b % a) != 0) {
                    b = a;
                    a = tmp;
                }
            }
        }
        System.out.println(a);
    }

}

Measured memory_bytes: 50736
from itertools import accumulate

N, K, *A = map(int, open(0).read().split())

M = [a if a < 0 else 0 for a in A]
P = [a if a > 0 else 0 for a in A]

MA = [0] + list(accumulate(M))
PA = [0] + list(accumulate(P))

minus = max(q - p for p, q in zip(MA, MA[K:]))
plus = min(q - p for p, q in zip(PA, PA[K:]))

print(sum(P) + max(minus, -plus))

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))




void solve(){
    ll n;cin>>n;
    ll a[n];
    rep(i,0,n)cin>>a[i];
    rep(i,1,n)a[i]+=a[i-1];
    ll ans=2*mod;
    rep(i,0,n-1)ans=min(ans,abs(a[n-1]-2*a[i]));
    cout<<ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;

    while(t--){
        solve();
    }
    return 0;
}


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

double n, m, d;

int main() {
	cin >> n >> m >> d;
	cout.precision(13);
	double ans = 2 * (n - d) / n;
	ans *= m - 1;	ans /= n;
	if (d == 0) {
		ans /= 2;
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
N = int(input())
blue = {}
for i in range(N):
    a = input()
    if a not in blue:
        blue[a] = 1
    else:
        blue[a] += 1
        
M = int(input())
#red = {}
for i in range(M):
    a = input()
    if a not in blue:
        blue[a] = -1
    else:
        blue[a] -= 1
print(max(0, max(blue.values())))

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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  
  req(i, 0, N){
    int l, r;
    cin >> l >> r;
    
    sum += (r - l + 1);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


int main()
{
    int H, N;
    cin >> H >> N;
    vector<int> dp(100000, 1e9);
    dp[0] = 0;
    while (N--) {
        int A, B;
        cin >> A >> B;
        REP(i, H) mmin(dp[i + A], dp[i] + B);
    }
    IREP(i, dp.size() - 1) mmin(dp[i], dp[i + 1]);
    cout << dp[H] << endl;
}


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

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

	long long n; cin >> n;
	map<long long, long long> cnt;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		long long x; cin >> x;
		ans += cnt[i - x];
		cnt[i + x]++;
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 26256
N = int(input())
num = list(map(int, input().split()))

xorsum = 0
sumz = 0
totallen = 0#N
right = 0
for left in range(N):
    while right < N and (sumz + num[right]) == (xorsum ^ num[right]):
        sumz += num[right]
        xorsum ^= num[right]
        right += 1

    totallen += (right - left)
    if right <= left:
        right += 1
    else:
        sumz -= num[left]
        xorsum ^= num[left]

print(totallen)



Measured memory_bytes: 100900
#include <iostream>
#include <vector>
using namespace std;
int main()
{
   int p,q,r;
   cin >> p >> q >> r;
int hai[]={p+q,p+r,q+r};
    int i;
    int min;
    int max;
    int ans;
 
    /* 代入 */
    min=hai[0];
    max=hai[0];
    ans=0;
 
    /* 計算 */
    for(i=0;i<=2;i++){/* 最大値求める */
        if(hai[i]>max)
        max=hai[i];
        /* 最小値求める */
        if(hai[i]<min)
        min=hai[i];
    }
  
       cout << min << endl;
      return 0;
 
}

Measured memory_bytes: 256
N = gets.chomp.to_i
Wn = (1..N).map { gets.chomp }

if Wn != Wn.uniq
  puts 'No'
  exit
end

for i in 0...N - 1 do
  w1 = Wn[i]
  w2 = Wn[i + 1]
  if w1[w1.length - 1] != w2[0]
    puts 'No'
    exit
  end
end

puts 'Yes'


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

const int NMAX = 100010;

typedef pair<int, int> ii;

int n, m, res = 0, last = 0;
ii a[NMAX];

bool cmp(ii x, ii y){
	return x.second < y.second;
}

int main(){
	cin >> n >> m;
	for (int i=1; i<=m; ++i){
		cin >> a[i].first >> a[i].second;
	}
	sort(a+1, a+1+m, cmp);
	for (int i=1; i<=m; ++i)
		if (a[i].first > last){
			res++;
			last = a[i].second-1;
		}
	cout << res;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
w = [input() for _ in range(n)]
h = [w[0]]
for i in range(1, n):
  if w[i] in h or w[i - 1][-1] != w[i][0]:
    print("No")
    break
  h.append(w[i])
else:
  print("Yes")

Measured memory_bytes: 3060
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int MAXN=100000;
vector<int> dist;
int a[MAXN+5];
int n,x,d;
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		dist.push_back(abs(a[i]-x));
	}
	for(int i=0;i<dist.size();i++)
		d=gcd(d,dist[i]);
	printf("%d\n",d);
    return 0;
}


Measured memory_bytes: 1148
#include<stdio.h>

int main()
{
  long int h,w;
  long long int ans;
  
  scanf("%ld %ld",&h,&w);
  
  if(h*w%2==0)
  {
    ans=h*w/2;
  }
  else
  {
    ans=h*w/2+1;
  }
  if(h==1||w==1)
  {
    ans=1;
  }
  printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main(){
    int n,q,query,x,t;;
    scanf("%d", &n);
    vector<int> A[n];
    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {        
        scanf("%d %d", &query,&t);
        switch (query){
            case 0:
                scanf("%d",&x);
                A[t].push_back(x);                       
                break;
            case 1:
            if (A[t].size()==0)
            {
                printf("\n");
            }else
            {           
            
                printf("%d",A[t][0]);
                for(int i = 1; i < A[t].size(); i++){
                    printf(" %d",A[t][i]);
                }
                    printf("\n");
            }
                break;
            case 2:
                A[t].clear();
                break;
            default:
                break;
        }
    }    
    return 0;
}


Measured memory_bytes: 5828
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int N, M, P; cin >> N >> M >> P;
		if (N == 0) break;
		vector<int> X(N);
		for (int i = 0; i < N; i++) cin >> X[i];
		int sum = 0;
		for (int i = 0; i < N; i++) sum += X[i];
		sum *= 100 - P;
		cout << (X[M - 1] ? sum / X[M - 1] : 0) << endl;
	}
}

Measured memory_bytes: 1200
h, w = map(int, input().split())
pict = [[0]*(w+2) for _ in range(h+2)]

for y in range(1, h+1):
    pict[y][1:w+1] = list(input())
ans = "Yes"
for y in range(h):
    for x in range(w):
        if pict[y][x] == "#":
            if pict[y-1][x] == "." and pict[y+1][x] == "." and pict[y][x-1] == "." and pict[y][x+1] == ".":
                ans = "No"
print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int limit = sc.nextInt();
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < a; i++) {
			int c = sc.nextInt();
			int t = sc.nextInt();
			if (t <= limit) {
				if (c < ans) {
					ans = c;
				}
			}
		}

		if (ans == Integer.MAX_VALUE) {
			System.out.println("TLE");
		} else {
			System.out.println(ans);
		}

	}

}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
#define pb push_back
#define ull unsigned long long
#define pii pair<int,int>
#define MP make_pair
typedef long long ll;
const ll INF=1e18;
const int inf=0x3f3f3f3f;
const int M=1e6+6;
int main(){
    string S,T;
    cin>>S>>T;
    int ans=inf;
    int lens=S.size(),lent=T.size();
    for(int i=0;i<lens;i++){
        int sum=0;
        if(i+lent-1>=lens)
            break;
        for(int j=0;j<lent;j++)
            if(S[i+j]!=T[j])
                sum++;
        ans=min(ans,sum);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
ll n,k;
cin>>n>>k;
if(k==1)
    cout<<0<<endl;
else
cout<<n-k<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int d; cin >> d;
    vector<int> ar(26);
    rep(i,26) cin >> ar[i];
    vector<vector<int>> sc(d,vector<int>(26));
    rep(i,d) rep(j,26) cin >> sc[i][j];
    vector<int> la(26,0);
    rep(i,d){
        int ma = -10000000;
        int as = 0;
        int ima = 0;
        rep(j,26){
            ima += ar[j] * (i+1 - la[j]);
        }
        rep(j,26){
            int sp = sc[i][j];
            sp -= ima;
            sp += ar[j] * (i+1 - la[j]);
            if (ma < sp){
                ma = sp;
                as = j+1;
            }
        }
        la[as-1] = i+1;
        cout << as << endl;
    }
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int a[27];
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<=3;i++)
		a[s[i]-'A'+1]++;
	int g=0;
	for(int i=1;i<=26;i++)
	{
		if(a[i])
		g++;
	}
	if(g!=2)
	{
		cout<<"No";
		return 0;
	}
	for(int i=1;i<=26;i++)
	{
		if(!(a[i]==2||a[i]==0))
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}

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

int main()
{
	string str = "";
	int H, W;
	cin >> H >> W;
	for (size_t i = 0; i < H; i++)
	{
		string s;
		cin >> s;
		str += s + "\n" + s + "\n";
	}
	cout << str << 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 PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int x, n;
	cin >> n >> x;
	vector<int>l(n);
	int i;
	int cnt = 1;
	int sum = 0;
	for (i = 0; i < n; i++)
	{
		cin >> l.at(i);
	}
	i = 2;
	while (n+1 >= i)
	{
		sum = sum + l.at(i - 2);
		if (sum <= x)
			cnt++;
		else
			break;
		i++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
void solve(){
    ll n ;
    cin >> n ;
    vector < ll > a(n) ;
    for( int i = 0 ; i < n ; i++) cin >> a[i] ;
    ll answer= 0 ;
    unordered_map < ll , ll > mp ;
    for( int i = 0 ; i < n ; i++) mp[a[i]]++;
    for( int i = 0 ; i < n ; i++){
        ll ans = 0 ;
        for( ll j = 1 ; j * j <= a[i] ; j++){
            if(a[i]%j==0){
                if(mp.find(j)!=mp.end()){
                    ans += mp[j] ;
                }
                if(a[i]/j != j ){
                    if(mp.find(a[i]/j)!=mp.end()){
                        ans += mp[a[i]/j];
                    }
                }
            }
        }
        //cout << ans << " " ;
        if(ans==1){
            answer++;
        }
    }
    cout << answer ;

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    int case1 = 1 ;
    while(t--){
        //cout << "Case #" << case1 << ": " ;
        case1++;
        solve( );
    }
}
//


Measured memory_bytes: 12964
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// 最大公約数
ll GCD(ll a, ll b)
{
    if (a < 0)
        a = -a;
    if (b < 0)
        b = -b;
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

// 最小公倍数
ll LCM(ll a, ll b)
{
    ll g = GCD(a, b);
    return a / g * b;
}

int main()
{
    int n;
    string in;
    cin >>n >> in;
    if (in.substr(0, n / 2) == in.substr(n / 2))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


ll solve(int N,int W,vi& w,vi& v) {
    vll dp(100001, LLONG_MAX); // ある価値が重さいくつで実現できるか
    dp[0] = 0;
    rep(i,N) {
        int wi = w[i], val = v[i];
        for (int j=100000; j>=val; --j) {
            if (dp[j-val] == LLONG_MAX) continue;
            amin(dp[j], dp[j-val] + wi);
        }
    }
    for (int i=100000; i>=0; --i) {
        if (dp[i] <= W) return i;
    }
    return 0;
}

int main() {
    int N,W; scanf("%d%d", &N, &W);
    vi w(N),v(N);
    rep(i,N) scanf("%d%d", &w[i], &v[i]);
    cout << solve(N,W,w,v) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int64 gcd(int64 a, int64 b) {
    return b != 0 ? gcd(b, a % b) : a;
}

int64 lcm(int64 a, int64 b) {
		return a / gcd(a, b) * b;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n, k; cin >> n >> k;
		vector<int> v(n);
		rep (i, n) {
			cin >> v[i];
		}
		int ans = 0;
		for (int l = 0; l <= k; ++l) {
			for (int r = 0; r <= (k - l); ++r) {
				if (l + r > n) break;
				int now = 0;
				vector<int> s;
				int d = k - l - r;
				for (int i = 0; i < l; ++i) {
					now += v[i];
					s.push_back(v[i]);
				}
				for (int i = n - r; i < n; ++i) {
					now += v[i];
					s.push_back(v[i]);
				}
				sort(all(s));
				rep (i, d) {
					if (i >= s.size()) break;
					if (s[i] > 0) break;
					now -= s[i];
				}
				ans = max(ans, now);
			}
		}
		cout << ans << endl;
    return;
}

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



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

using namespace std;

const int inf = 1000000007;

int main(){
    set<char> s;
    string a;
    cin >> a;
    for(int i=0;i<4;i++){
        s.insert(a[i]);
    }
    if(s.size() == 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 A, B, K;
  std::cin >> A >> B >> K;
  for (i64 i = std::min(A, B); i >= 1; --i) {
    if (A % i == 0 && B % i == 0) {
      --K;
      if (K == 0) {
        std::cout << i << std::endl;
        return 0;
      }
    }
  }
  return EXIT_FAILURE;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
d = {i:[] for i in range(1,n+1)}
for i,num in enumerate(a):
    d[num].append(i+2)
ans = []
for i in range(1,n+1):
    ans.append(len(d[i]))
write("\n".join(map(str, ans)))

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

int main(){
  int n,k;
  cin >> n >> k;
  set<int> s;
  
  for(int i = 0;i < k;i ++){
    int d;
    cin >> d;
    for(int j = 0;j < d;j ++){
      int a;
      cin >> a;
      s.insert(a);
    }
  }
  
  cout << n - s.size() << endl;
}

Measured memory_bytes: 3624
package main

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
)

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
}

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	n, _ := strconv.Atoi(ReadString())
	return n
}

func readInt64() int64 {
	n, _ := strconv.ParseInt(ReadString(), 0, 64)
	return n
}

// 10 11 12 => [10, 11, 12]
func readIntSlice(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; i++ {
		a[i] = readInt()
	}
	return a
}

func get2byte(size int) [][]byte {
	a := make([][]byte, size)
	for i := 0; i < size; i++ {
		var low string
		fmt.Scan(&low)
		a[i] = []byte(low)
	}
	return a
}

func transpose(a [][]int) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a[i][j], a[j][i] = a[j][i], a[i][j]
		}
	}
}

func fact(n, m int) int {
	res := 1
	for i := m + 1; i <= n; i++ {
		res *= i
	}
	return res
}

func perm(n, r int) int {
	if r > n {
		return 0
	}
	return fact(n, n-r)
}

func comb(n, m int) int {
	if m > n {
		return 0
	}
	return fact(n, n-m) / fact(m, 0)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

func main() {
	k := readInt()
	a, b := readInt(), readInt()
	flag := false
	for i := 1; i <= 1000; i++ {
		if a <= k*i && k*i <= b {
			flag = true
		}
	}

	if flag {
		fmt.Println("OK")
	} else {
		fmt.Println("NG")
	}
}


Measured memory_bytes: 1756
//http://abc057.contest.atcoder.jp/tasks/abc057_a

#include <bits/stdc++.h>

using namespace std;

signed main(signed arg, char *args[])
{
    int A, B;
    int ans;
    cin >> A >> B;
    ans = A + B;
    cout << ans % 24 << endl;
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, P> PP;

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

int k;
deque<int> dq;
int d[100005];

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

	cin>>k;
	d[1]=1;
	dq.pb(1);
	while (dq.front()) {
		int v=dq.front(); dq.pop_front();
		REP(i,2) {
			int u=(i?v+1:v*10)%k;
			if(d[u]&&d[u]<=d[v]+i) continue;
			d[u]=d[v]+i;
			i?dq.pb(u):dq.pf(u);
		}
	}
	cout<<d[0]<<endl;

	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    double x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    printf("%f\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    return 0;
}


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



string S, T;
int cntS[101010], cntT[101010];
//-----------------------------------------------------------------------------------
int main() {
    cin >> S >> T;

    rep(i, 0, S.length()) if (S[i] == 'A') cntS[i] = 1;
    rep(i, 1, S.length()) cntS[i] += cntS[i - 1];
    rep(i, 0, T.length()) if (T[i] == 'A') cntT[i] = 1;
    rep(i, 1, T.length()) cntT[i] += cntT[i - 1];

    int Q; cin >> Q;
    rep(q, 0, Q) {
        int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
        a--; b--; c--; d--;

        int cnt, s, t;

        cnt = cntS[b];
        if (0 < a) cnt -= cntS[a - 1];
        s = cnt + (b - a + 1 - cnt) * 2;

        cnt = cntT[d];
        if (0 < c) cnt -= cntT[c - 1];
        t = cnt + (d - c + 1 - cnt) * 2;

        if (s % 3 == t % 3) printf("YES\n");
        else printf("NO\n");
    }
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
  int a[10][10],i,j;
  while(scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d",
              &a[0][0],&a[0][1],&a[0][2],&a[0][3],&a[0][4],
	      &a[0][5],&a[0][6],&a[0][7],&a[0][8],&a[0][9])!=EOF){
    for(i=0;i<9;i++){
      for(j=0;j<9-i;j++){
	a[i+1][j]=(a[i][j]+a[i][j+1])%10;
      }
    }
    printf("%d\n",a[9][0]);
  }
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	int A[520][520] = {}; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			int tmp = (i ^ j); 
			int count = 0; 
			while(tmp > 0){
				tmp >>= 1; count ++; 
			}
			A[i][j] = count; 
		}
	}
	for(int i = 0; i < N; i++){
		for(int j = i+1; j < N; j++){
			cout << A[i][j] << " "; 
		}
		cout << endl; 
	}
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);
    rep(i, m) cin >> l[i] >> r[i];
    int x = l[0], y = r[0];
    for (int i = 1; i < m;i++){
        if(x<=l[i])
            x = l[i];
            
            if(r[i]<=y)
                y = r[i];
    }
    if(x<=y)
        cout << y - x + 1 << endl;
        else
            cout << 0 << endl;
        return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var x = Console.ReadLine ().Split (' ').Select (long.Parse).ToArray ();
			var ans = Ans (x);
			x = new[]{ x [1], x [0] };
			ans = Math.Min (ans, Ans (x));
			Console.WriteLine (ans);
		}

		static long Ans (long[] x)
		{
			var area = new long[3];
			var result = long.MaxValue;
			if (x [0] % 3 == 0 || x [1] % 3 == 0)
				return 0;
			else {
				for (int i = 1; i < x [0]; i++) {
					area [0] = i * x [1];
					area [1] = x[1] * ((x [0]-i) / 2);
					area [2] = x [0] * x [1] - area [0] - area [1];
					var hoge = Max (area) - min (area);
					if (hoge < result)
						result = hoge;
					area [1] = (x [0] - i) * (x [1] / 2);
					area [2] = x [0] * x [1] - area [0] - area [1];
					hoge = Max (area) - min (area);
					if (hoge < result)
						result = hoge;
				}
			}
			return result;
		}

		public static long Max (long[] a)
		{
			var max = a [0];
			for (int i = 1; i < a.Length; i++) {
				if (a [i] > max)
					max = a [i];
			}
			return max;
		}

		public static long min (long[] a)
		{
			var min = a [0];
			for (int i = 1; i < a.Length; i++) {
				if (a [i] < min)
					min = a [i];
			}
			return min;
		}
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

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

  int a = n % 10;

  if (a == 3) {
    cout << "bon" << endl;
  } else if (a == 1 || a == 6 || a == 8 || a == 0) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}

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

bool isKaibun(string S, int sMoji, int lMoji)
{
  string subS = S.substr(sMoji, lMoji);
  string orderS = subS;
  reverse(subS.begin(), subS.end());

  int result = orderS.compare(subS);

  if (result == 0)
  {
    return true;
  }
  else
  {
    return false;
  }
}

int main()
{
  string S;

  cin >> S;

  int N = S.length();

  if (isKaibun(S, 0, N) && isKaibun(S, 0, (N - 1) / 2) && isKaibun(S, ((N + 3) / 2) - 1, (N + 1) - (N + 3) / 2))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from math import gcd
from functools import reduce
from itertools import product
import numpy as np

def resolve():
  X, Y = map(int, input().split(" "))
  if Y%2 != 0:
    print("No")
    return True
  if Y < (2*X):
    print("No")
    return True
  if Y > (4*X):
    print("No")
    return True
  print("Yes")

if __name__ == "__main__":
  resolve()

Measured memory_bytes: 27136
#include <bits/stdc++.h>
using namespace std;
 
const int MAX = 2e5;
const int64_t MOD = 1e9 + 7;
int64_t fac[MAX] = {}, inv[MAX] = {}, finv[MAX] = {};
 
void make_table() {
  fac[0] = 1; fac[1] = 1;
  finv[0] = 1; finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
 
int64_t com(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  make_table();
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    cout << com(N - K + 1, i) * com(K - 1, i - 1) % MOD << endl;
  }
}

Measured memory_bytes: 4992
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;
}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_C() {}

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

    string S; cin >> S;
    
    string r = S;
    reverse(r.begin(), r.end());
    string ptn[4] = {"maerd", "remaerd", "esare", "resare"};

    while(r.size()>0) {
        bool match = false;
        int N = r.size();
        for (string p : ptn){
            int L = p.size();
            string t = r.substr(0, L);
            if (p == t) {
                r = r.substr(L, N);
                match = true;
                break;
            }
        }
        if (!match) break;
    }

    string ans = r.size()==0 ? "YES" : "NO";
    cout << ans << endl;  

    return 0;
}

Measured memory_bytes: 720
import sys
n=input()
a=map(int, raw_input().split())
diff=[a[(i+1)%n]-a[i] for i in range(n)]
cnt=max(diff)
diff=[value-cnt for value in diff]
start=[]
for value in diff:
	if value%n:
		print "NO"
		exit()
	else:
		start.append(-value/n)
cnt=sum(start)
b=[0]
for i in range(n):
	b[0]+=start[i]*(n-i)
for i in range(n):
	b.append(b[-1]+cnt-start[i]*n)
assert b[0]==b[-1]
b=b[:-1]
for i in range(n):
	if (a[i]-b[i])%(n*(n+1)/2) or a[i]<b[i]:
		print "NO"
		exit()
print "YES"

Measured memory_bytes: 19196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
struct Elm {
  int t, city, rem;
};
bool operator< (Elm e1, Elm e2) {
  return e1.t > e2.t;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int n, m, l, k, a, h; cin >> n >> m >> l >> k >> a >> h;
    if(n == 0) break;
    vector<bool> reito(n, false);
    for(int i=0;i<l;++i) {
      int tmp; cin >> tmp;
      reito[tmp] = true;
    }
    vector<vector<P>> g(n);
    for(int i=0;i<k;++i) {
      int u, v, c; cin >> u >> v >> c;
      g[u].push_back({v, c});
      g[v].push_back({u, c});
    }
    vector<vector<int>> dp(n, vi(m+1, INF));
    dp[a][m] = 0;
    priority_queue<Elm> pq;
    pq.push({0, a, m});
    while(!pq.empty()) {
      Elm now = pq.top(); pq.pop();
      if(now.t > dp[now.city][now.rem]) continue;
      for(int i=0;i<(int)(g[now.city].size());++i) {
        int to = g[now.city][i].first, cost = g[now.city][i].second;
        if(now.rem < cost) continue;
        if(dp[to][now.rem - cost] > now.t + cost) {
          dp[to][now.rem - cost] = now.t + cost;
          pq.push({dp[to][now.rem - cost], to, now.rem - cost});
        }
        if(!reito[to]) continue;
        int tmp = now.rem - cost + 1;
        while(tmp <= m && dp[to][tmp] > dp[to][tmp-1] + 1) {
          dp[to][tmp] = dp[to][tmp-1] + 1;
          pq.push({dp[to][tmp], to, tmp});
          tmp++;
        }
      }
    }
    int ans = INF;
    for(int i=0;i<=m;++i) {
      ans = min(ans, dp[h][i]);
    }
    if(ans == INF) cout << "Help!" << endl;
    else cout << ans << endl;
  }
}



Measured memory_bytes: 3440
#include <stdio.h>

int BubbleSort ( int* Arr, int Max_order );
int SelectionSort ( int* Arr, int Max_order );

int main ( void ) {
    int Max_order = 0;
    int Arr[100] = {};
    int i = 0;
    int count_for_swap = 0;
    
    
    scanf( "%d", &Max_order );
    for ( i = 0; i < Max_order; i++ ) {
        scanf ( "%d ", &Arr[i] );
    }
    
    count_for_swap = SelectionSort ( Arr, Max_order );
    
    for ( i = 0; i < Max_order - 1; i++ ) {
        printf( "%d ", Arr[i] );
    }
    printf( "%d\n", Arr[i] );
    printf( "%d\n", count_for_swap );
    return 0;
}

int BubbleSort ( int* Arr, int Max_order )
{
    int count_for_swap = 0;
    int tmp = 0;
    int i = 0;
    int j = 0;
    
    for ( i = 0; i < Max_order; i++ ) {
        for ( j = Max_order - 1; j > i; j-- ) {
            if ( Arr[j] < Arr[j-1] ) {
                tmp = Arr[j];
                Arr[j] = Arr[j-1];
                Arr[j-1] = tmp;
                count_for_swap++;
            }
        }
    }
    
    return count_for_swap;
}

int SelectionSort ( int* Arr, int Max_order )
{
    int count_for_swap = 0;
    int tmp = 0;
    int mini = 0;
    int i = 0;
    int j = 0;
    
    for ( i = 0; i < Max_order; i++ ) {
        mini = i;
        for ( j = i; j < Max_order; j++ ) {
            if ( Arr[j] < Arr[mini] ) {
                mini = j;

            }
            
        }
        
        if ( i != mini ) {
            tmp = Arr[i];
            Arr[i] = Arr[mini];
            Arr[mini] = tmp;
            count_for_swap++;
        }
            

    }
    
    return count_for_swap;
    
}


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

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


Measured memory_bytes: 3532
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author varunvats32
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ANextAlphabet solver = new ANextAlphabet();
        solver.solve(1, in, out);
        out.close();
    }

    static class ANextAlphabet {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String c = in.next();
            out.println((char) (c.charAt(0) + 1));
        }

    }
}



Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

struct triple
{
    ll val;
    int lef, rig;
    triple(ll a = 0, int b = 0, int c = 0) {val = a, lef = b, rig = c;}
};

struct My_stack
{
    triple mas[200005];
    int tail = 0;
    ll sum = 0;
    void clear()
    {
        sum = 0, tail = 0;
        return;
    }
    void add(ll val, int lef, int rig)
    {
        while (tail > 0 && val <= mas[tail].val)
        {
            sum -= (ll) (mas[tail].rig - mas[tail].lef + 1) * mas[tail].val;
            lef = min(lef, mas[tail].lef), rig = max(rig, mas[tail].rig);
            tail--;
        }
        tail++;
        mas[tail] = triple(val, lef, rig);
        sum += (ll) (mas[tail].rig - mas[tail].lef + 1) * mas[tail].val;
        return;
    }
    ll get_sum()
    {
        return sum;
    }
};

ll a[200005], step[200005], suf[200005], st[200005], pref[200005];
My_stack S;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    ll sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    step[1] = 0;
    for (int i = 2; i <= n; i++)
    {
        if (a[i - 1] <= a[i])
        {
            int h = 0;
            while (a[i - 1] * (1ll << h) < a[i]) h += 2;
            if (a[i - 1] * (1ll << h) == a[i])
                step[i] = max(step[i - 1] - (ll) h, 0ll);
            else
                step[i] = max(step[i - 1] - (ll) h + 2, 0ll);
        }
        if (a[i - 1] > a[i])
        {
            int h = 0;
            while (a[i] * (1ll << h) < a[i - 1]) h += 2;
            step[i] = step[i - 1] + (ll) h;
        }
    }
    S.clear();
    for (int i = n; i > 0; i--)
    {
        S.add(step[i], i, i);
        sum += step[i];
        suf[i] = sum - S.get_sum();
    }
    suf[n + 1] = 0;

    for (int i = 1; i <= n; i++) a[i] *= (-2), st[i] = 1;
    for (int i = n - 1; i > 0; i--)
    {
        if (a[i] <= a[i + 1])
        {
            int h = 0;
            while (a[i + 1] * (1ll << h) > a[i]) h += 2;
            if (a[i + 1] * (1ll << h) == a[i])
                st[i] = max(st[i + 1] - (ll) h, 1ll);
            else
                st[i] = max(st[i + 1] - (ll) h + 2, 1ll);
        }
        if (a[i] > a[i + 1])
        {
            int h = 0;
            while (a[i] * (1ll << h) > a[i + 1]) h += 2;
            st[i] = st[i + 1] + (ll) h;
        }
    }
    S.clear();
    sum = 0;
    for (int i = 1; i <= n; i++)
    {
        S.add(st[i] - 1, i, i);
        sum += st[i];
        pref[i] = sum - S.get_sum();
    }
    pref[0] = 0;
    ll answer = (ll) 1e18;
    for (int i = 0; i <= n; i++) answer = min(answer, pref[i] + suf[i + 1]);
    cout << answer;
    return 0;
}



Measured memory_bytes: 11264
MOD = 10**9+7

def factorial_mod(n, mod=MOD):
    ret = 1
    for k in range(1,n+1):
        ret = (ret*k) % mod
        
    return ret

N,M = map(int,input().split())
N_fact = factorial_mod(N)
M_fact = factorial_mod(M)
ret = (N_fact*M_fact)%MOD

if  N-M == 0:
    ret = (2*ret)%MOD
elif abs(N-M) == 1:
    pass
else:
    ret = 0
    
print(ret)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=5e3+20;
ll n,m;
string s;
ll dp[N][N];
ll powmod(ll x,ll n)
{
	ll s=1;
	while(n)
	{
		if(n&1)
			s=(s*x)%mod;
		x=(x*x)%mod;
		n>>=1;
	}
	return s;
}
int main()
{
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=0;i<=5000;i++)
	{
		for(int j=0;j<=5000;j++)
		{
			if(dp[i][j]==0) continue;
			dp[i+1][j+1]=(dp[i+1][j+1]+(2ll*dp[i][j])%mod)%mod;
			(dp[i+1][max(0,j-1)]+=dp[i][j]%mod)%=mod;	
		}
	}
	while(cin>>n>>s)
	{
		ll l=s.length();
		ll ans=dp[n][l];
		ll t=powmod(2ll,l); 
		ans=(ans*powmod(t,mod-2))%mod;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 197120
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


X = ini()


def solve():
    if X < 600:
        return 8
    if X < 800:
        return 7
    if X < 1000:
        return 6
    if X < 1200:
        return 5
    if X < 1400:
        return 4
    if X < 1600:
        return 3
    if X < 1800:
        return 2
    return 1


print(solve())


Measured memory_bytes: 9200