akhauriyash/Code-Regression huggingface dataset:
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<usize>();
    let (k, t)= (line[0], line[1]);
    let a = read_as_vec::<u64>();

    let max: u64 = *a.iter().max().unwrap();
    let sum: u64 = a.iter().sum::<u64>();
    // max - (sum-max) = 2max - sum;
    // 2*4 - 6
    if sum - max < max{
        println!("{}", 2*max-sum -1);
    }else{
        println!("0");
    }
}


Measured memory_bytes: 4352
import collections as c
ip = lambda : map(int, input().split())

##############
r,g,b,n = ip()
ans = 0

for i in range(n//r+1):
    for j in range((n-i*r)//g+1):
        
        if (n-i*r-j*g)%b == 0:
            ans += 1
print(ans)

Measured memory_bytes: 3444
import copy
N,W = map(int,input().split())
w = []
v = []
for i in range(N):
    x,y = map(int,input().split())
    w.append(x)
    v.append(y)

d = [0]*(W+1)
dp = [copy.deepcopy(d) for j in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i])

print(dp[N][W])

Measured memory_bytes: 141940
n = int(input())
bl = list(map(int, input().split()))

curr_bl = bl[:]

ans = []
for i in range(n):
    rem = n - i
    deleted_j = -1
    for j in range(rem-1,-1,-1):
        if curr_bl[j] == j+1:
            deleted_j = j
            ans.append(j+1)
            break
    if deleted_j == -1:
        print(-1)
        exit()
    else:
        new_bl = []
        for j in range(rem):
            if j != deleted_j:
                new_bl.append(curr_bl[j])
        curr_bl = new_bl[:]


for a in ans[::-1]:
    print(a)

Measured memory_bytes: 64788
#include <iostream>
using namespace std;
  
int main(){
  int n,m,c,i,j,ans=0,sum;
  cin >> n >> m >> c;
  int a[m],b[m];
  for(j=0;j<m;j++){
    cin >> b[j];
  }
  for(i=0;i<n;i++){
    sum = 0;
    for(j=0;j<m;j++){
      cin >> a[j];
      sum += a[j] * b[j];
    }
    sum += c;
    if(sum > 0){
      ans += 1;
    }
  }
  cout << ans << endl;
}
  


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int N, M;
	cin >> N >> M;
	
	VI A(N);
	VI B(N);
	VI C(N);
	VI D(N);
	VI E(N);
	VI F(N);
	VI G(N);
	VI H(N);

	REP(i, N) {
		int a, b, c;
		cin >> a >> b >> c;
		A[i] = a + b + c;
		B[i] = a + b - c;
		C[i] = a - b + c;
		D[i] = a - b - c;
		E[i]=-1* a + b + c;
		F[i] = -1 * a + b - c;
		G[i] = -1 * a - b + c;
		H[i] = -1 * a - b - c;
	}
	rSORT(A);
	rSORT(B);
	rSORT(C);
	rSORT(D);
	rSORT(E);
	rSORT(F);
	rSORT(G);
	rSORT(H);
	VI ans(8, 0);
	REP(i, M) 
		ans[0] += A[i];
	REP(i, M)
		ans[1] += B[i];
	REP(i, M)
		ans[2] += C[i];
	REP(i, M)
		ans[3] += D[i];
	REP(i, M)
		ans[4] += E[i];
	REP(i, M)
		ans[5] += F[i];
	REP(i, M)
		ans[6] += G[i];
	REP(i, M)
		ans[7] += H[i];
	rSORT(ans);

	cout << ans[0] << endl;

	return 0;
}



Measured memory_bytes: 384
# coding:utf-8

import sys
from bisect import bisect_left, bisect_right

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, a, b, c, d = LI()

    base = [-INF]
    if n % 2:
        base += list(reversed([a - (2 * c + d - c) * i for i in range(1, (n + 1) // 2)])) + [a + (2 * c + d - c) * i for i in range((n + 1) // 2)]
    else:
        base += list(reversed([a - (d + c) // 2 - (2 * c + d - c) * i for i in range(n // 2)])) + [a + (d + c) // 2 + (2 * c + d - c) * i for i in range(n // 2)]
    base += [INF]

    near = bisect_left(base, b)
    # print(base)
    # print(b, near)

    l = base[near - 1]
    r = base[near]
    x = l if b - l <= r - b else r
    # print(l, r, x)
    if n % 2:
        tmp = ((n + 1) // 2 - 1) * (d - c)
        # print(tmp)
        if x - tmp <= b <= x + tmp:
            res = 'YES'
        else:
            res = 'NO'
    else:
        tmp = (n // 2 - 1) * (d - c) + (d - c) // 2
        # print(tmp)
        if (d - c) % 2:
            if a <= b:
                if x - tmp <= b <= x + tmp + 1:
                    res = 'YES'
                else:
                    res = 'NO'
            else:
                if x - tmp - 1 <= b <= x + tmp:
                    res = 'YES'
                else:
                    res = 'NO'
        else:
            if x - tmp <= b <= x + tmp:
                res = 'YES'
            else:
                res = 'NO'

    return res


print(main())


Measured memory_bytes: 30580
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>

using namespace std;
long long n,a,b;
long long h[100000];

bool check(int p) {
  int p_left = p;
  bool good = true;
  long long z = a - b, zz, need_a;
  for (int i = 0; (i < n) && good; i++) {
    if (h[i] > b*p) {
      zz = h[i] - p*b;

      need_a = zz / z;
      if (zz % z) {
        need_a++;
      }
      good = need_a <= p_left;
      p_left -= need_a;
    }
  }

  return good;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  priority_queue<int, vector<int> > heap;
  cin >> n >> a >> b;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  long long l = 0, r = 1000000001;
  long long mid;
  while (r-l > 1) {
    mid = (r + l) /2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }

  cout << r << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (210)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c)&&c!='.'&&c!='#';c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c){
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,m,f[2][N][N][N]; char a[N][N];
int main(){
	read(n),read(m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)readc(a[i][j]);
	for(int i=n;i;i--)
	for(int j=i;j<=n;j++)
	for(int k=m;k;k--)
	if(i==j){
		if(k==m)f[0][i][j][k]=m+1;
		else f[0][i][j][k]=(a[i][k]==a[i][k+1])?f[0][i][j][k+1]:k+1;
	}
	else f[0][i][j][k]=(a[i][k]==a[i+1][k])?min(f[0][i][i][k],f[0][i+1][j][k]):k;
//	for(int i=1;i<=n;i++)
//	for(int j=i;j<=n;j++)
//	for(int k=1;k<=m;k++)
//	cout<<i<<" "<<j<<" "<<k<<" "<<f[0][i][j][k]<<endl;
//	puts("---------------");
	for(int ans=0,p=0,t=1;;p^=1,t^=1,ans++){
		if(f[p][1][n][1]==m+1){printf("%d\n",ans);break;}
		for(int i=n;i;i--)
		for(int j=i;j<=n;j++)
		for(int k=m;k;k--){
			f[t][i][j][k]=(f[p][i][j][k]==m+1)?m+1:f[p][i][j][f[p][i][j][k]];
			if(i<j){
				int L=i,R=j-1;
				while(L<=R){
					int mid=(L+R)>>1;
					if(f[p][i][mid][k]<=f[p][mid+1][j][k])
					f[t][i][j][k]=max(f[t][i][j][k],f[p][i][mid][k]),R=mid-1;
					else f[t][i][j][k]=max(f[t][i][j][k],f[p][mid+1][j][k]),L=mid+1;
				}
			}
//			cout<<i<<" "<<j<<" "<<k<<" "<<f[t][i][j][k]<<endl;
		}
//		puts("-------------------");
	}
}

Measured memory_bytes: 69632
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LN 20  
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 (int)1e9+2
# define maxn 100006
# define offset 1005

/*************************************************
struct Coupon {
    ll l;
    ll r;
    ll id;

    Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

    bool operator<(const Coupon& c) { // Sorting
        return l < c.l;    
    }
};

**************************************************/
int main()
{
  int n;
  cin >> n;
  int ans=0;
  int a[n];
  for(int i=0;i<n;i++)
    { 
        cin >> a[i];
        ans+=(a[i]-1);
    } 

  cout << ans;
}

Measured memory_bytes: 256
H,N=map(int, input().split())
A=list(map(int, input().split())) 
A.sort(reverse=True)
for i in range(len(A)):
    if H>0:
        H=H-A[i]
    else:
        break
if H<=0:
    print("Yes")
else:
    print("No")

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



int main(){
  
  int n; cin>>n;
  
  string s[n];
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  
  for(int i=0;i<n;i++){
    bool endf=false;
    while(!endf){
      endf=true;
      for(int j=1;j<10;j++){
        if(s[i][j-1] > s[i][j]){
          char temp=s[i][j-1];
          s[i][j-1]=s[i][j];
          s[i][j]=temp;
          endf=false;
        }
      }
    }
  }
  
  sort(s, s+n);
  
  vector<long long> v;
  int cnt=1;
  for(int i=1;i<n;i++){
    if(s[i]==s[i-1]){
      cnt++;
    }
    else if(cnt!=1){
      v.push_back(cnt);
      cnt=1;
    }
    if(i==n-1 && cnt!=1){
      v.push_back(cnt);
    }
  }
   
  
  long long ans = 0;
  for(auto x : v){
    ans += x*(x-1)/2;
  }

  cout << ans;
return 0;
}

Measured memory_bytes: 7552
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int> input(210);
	for (int i = 0; i < N; i++) {
		cin >> input.at(i);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			int diff = abs(input.at(i) - input.at(j));
			if (diff >= ans) {
				ans = diff;
			}
		}
	}

	cout << ans;

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template Start)*****
#define endl "\n"
#define ll long long
#define fo(i,n)                     for(i=0;i<n;i++)
#define Fo(i,n)                     for(i=1;i<=n;i++)
#define si(x)                       scanf("%d",&x)
#define sl(x)                       scanf("%lld",&x)
#define ss(s)                       scanf("%s",s)
#define pi(x)                       printf("%d\n",x)
#define pl(x)                       printf("%lld\n",x)
#define ps(s)                       printf("%s\n",s)
#define all(x)                      x.begin(),x.end()
#define allr(x)                     x.rbegin(),x.rend()
#define sortAll(x)                  sort(all(x))   
#define clearAll(arr)               memset(arr,0,sizeof(arr))
#define deb(sum)                    cout<<"deb = "<<sum<<endl;
#define pb                          push_back
#define mp                          make_pair
#define F                           first
#define S                           second
#define PI                          3.1415926535897932384626
typedef pair<int, int>              pii;
typedef pair<long long, long long>  pll;
typedef vector<int>                 vi;
typedef vector<long long>           vl;
typedef vector<pii>                 vpii;
typedef vector<pll>                 vpll;
#define kedar ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll mod=1000000007;
ll powerMod(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
	if (n & 1)
	  res = (res * x) % mod;
	x = (x * x) % mod;
	n >>= 1;
  }
  return res;
}

ll power(ll x, ll n) {
  ll res = 1;
  while (n) {
	if (n & 1)
	  res = (res * x);
	x = (x * x);
	n >>= 1;
  }
  return res;
}

int gcd(int A, int B) {
    if(B==0)
        return A;
    else
        return gcd(B, A % B);
}
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template ends)*****
//  <<,
//  , cout<<<<endl;
int dp[1005][1005];
void solve()
{
  int n, m;
  cin>>n>>m;
  string arr[n];
  for (int i = 0; i < n; i++)
  {
   cin>>arr[i];
  }
  
  dp[0][0]=1;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      if(arr[i][j]=='#') continue;
      if(i-1>=0) dp[i][j] = (dp[i-1][j] + dp[i][j])%mod;
      if(j-1>=0) dp[i][j] = (dp[i][j-1] + dp[i][j])%mod;
    }
  }
  
  cout<<dp[n-1][m-1];
}

int main(){
    kedar;
// <<
//  <<,
//  ,

    ll t=1;
    //cin>>t;
    while(t--)
    {     
        solve();
    }
    return 0;
}// <<
//  <<,
//  ,


Measured memory_bytes: 5248
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; ll c; cin >> n >> c;
  vector<ll> x(n);
  vector<ll> v(n);
  rep(i,n) cin >> x[i] >> v[i];
  vector<ll> right(n);
  vector<ll> left(n);
  right[0]=v[0]-x[0];
  left[n-1]=v[n-1]-(c-x[n-1]);
  for(int i=1;i<n;i++) right[i]=v[i]+right[i-1]-(x[i]-x[i-1]);
  for(int i=n-2;i>=0;i--) left[i]=v[i]+left[i+1]-(x[i+1]-x[i]);
  vector<ll> r_l(n);
  vector<ll> l_r(n);
  ll mx=0;
  r_l[n-1]=right[n-1];
  for(int i=n-2;i>=0;i--){
    chmax(mx,left[i+1]);
    chmax(r_l[i],max(right[i],right[i]+mx-x[i]));
  }
  mx=0;
  l_r[0]=left[0];
  for(int i=1;i<n;i++){
    chmax(mx,right[i-1]);
    chmax(l_r[i],max(left[i],left[i]+mx-(c-x[i])));
  }
  ll ans=0;
  rep(i,n){
    chmax(ans,r_l[i]);
    chmax(ans,l_r[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
INF = float('inf')

N, u, v = map(int, input().split())
u, v = u-1, v-1
adjL = [[] for _ in range(N)]
for _ in range(N-1):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    adjL[A].append(B)
    adjL[B].append(A)

def bfsMinCosts(adjList, vSt, INF):
    numV = len(adjList)
    costs = [INF] * numV
    costs[vSt] = cost = 0
    vs = [vSt]
    while vs:
        cost += 1
        v2s = []
        for v in vs:
            for v2 in adjList[v]:
                if costs[v2] == INF:
                    costs[v2] = cost
                    v2s.append(v2)
        vs = v2s
    return costs

costUs = bfsMinCosts(adjL, u, INF)
costVs = bfsMinCosts(adjL, v, INF)

maxC = -1
vMaxC = -1
for v, (costU, costV) in enumerate(zip(costUs, costVs)):
    if costU >= costV: continue
    if costV > maxC:
        maxC = costV
        vMaxC = v

print(maxC-1)


Measured memory_bytes: 27440
W, H, N = map(int, input().split())


# x, y軸を作る
w = [1] * (W)
h = [1] * (H)

for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        w[:x] = [0] * x
    elif a == 2:
        w[x:] = [0] * (H - x)
    elif a == 3:
        h[:y] = [0] * y
    elif a == 4:
        h[y:] = [0] * (H - y)

ans = sum(w) * sum(h)
print(ans)


Measured memory_bytes: 38384
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        cs: chars,
    }
    println!("{}", cs.iter().filter(|&&c| c == '1').count());
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{

	int a, b, c;
	int e;
	scanf("%d %d %d", &a, &b, &c);
	if (a >= b) {
		e = a;
		a = b;
		b = e;
	}
	if (b >= c) {
		e = b;
		b = c;
		c = e;
	}
	if (a >= b) {
		e = a;
		a = b;
		b = e;
	}
	printf("%d %d %d\n", a, b, c);

	return 0;
}


Measured memory_bytes: 2104
import sys
input = sys.stdin.readline
n, k = map(int,input().split())
A = list(map(int,input().split()))

s = sum(A)
D = []
for i in range(1, int(s**0.5) + 1):
    if s % i == 0:
        D.append(i)
        if i != s//i:
            D.append(s//i)
D.sort(reverse=True)

for i in range(len(D)):
    B = {}
    for j in range(n):
        try:
            B[A[j] % D[i]] += 1
        except:
            B[A[j] % D[i]] = 1
    C = list(B.items())
    C.sort()
    # print(D[i], C)
    E = []
    for j in range(len(C)):
        E.append([C[j][0], C[j][1]])
    nn = n
    c = 0
    
    l = 0
    r = len(E)-1
    ls = 0
    rs = 0
    while nn > 0:
        if ls <= rs:
            ls += E[l][0]
            E[l][1] -= 1
            nn -= 1
            if E[l][1] == 0:
                l += 1
        else:
            rs += D[i] - E[r][0]
            E[r][1] -= 1
            nn -= 1
            if E[r][1] == 0:
                r -= 1
    # print(ls,rs)
    if ls <= k:
        print(D[i])
        break

Measured memory_bytes: 50012
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}

int n;ll a[25]; 
ll solve(int l,int r,ll x,ll y) {
	if(l>r) return 0;
	ll ans=1e18;
	for(int i=l;i<=r;++i)
		ans=min(ans,solve(l,i-1,x,x+y)+solve(i+1,r,x+y,y)+(x+y)*a[i]);
	return ans;
}
int main() {
	IN(n);
	for(int i=1;i<=n;++i) IN(a[i]);
	printf("%lld\n",a[1]+a[n]+solve(2,n-1,1,1));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
  int n,a[100];
  int i,j,flag,tmp,sum;

  scanf("%d",&n);
  for(j=0;j<n;j++)scanf("%d",&a[j]);

  flag=1;
  i=0;
  while(flag){
    flag=0;
    for(j=n-1;j>=i+1;j--){
      if(a[j]<a[j-1]){
	tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
	sum++;
      }
      flag=1;
    }
    i++;
  }

  for(j=0;j<n;j++){
    printf("%d",a[j]);
    if(j!=n-1)printf(" ");
  }

  printf("\n%d\n",sum);
  return 0;
}

Measured memory_bytes: 604
#include <cstdio>

using namespace std;

int main()
{
  char c;
  int n;
  while ((c = getchar()) != EOF) {
    if ('0' <= c && c <= '9') {
      int m = c - '0';
      while ((c = getchar()) != EOF && '0' <= c && c <= '9') {
	m = m * 10 + c - '0';
      }
      n += m;
    }
  }
  printf("%d\n", n);
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>

int main(void)
{
    int q;
    double x;

    while (scanf("%d", &q) + q != 0){
        x = q / 2.0;
        while (1e-5 * q <= fabs(x * x * x - q)){
            x = x - (x * x * x - q) / (3 * x * x);
        }
        printf("%f\n", x);
    }

    return (0);
}

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

using RInt=array<int,256>;
int main(){
    int m;
    cin>>m;
    map<string,RInt> var;
    for(int i=0;i<m;i++){
        string name;
        int lb,ub;
        cin>>name>>lb>>ub;
        for(int j=0;j<lb;j++) var[name][j]=0;
        for(int j=lb;j<=ub;j++) var[name][j]=1;
        for(int j=ub+1;j<256;j++) var[name][j]=0;
    }
    int n;
    cin>>n;
    vector<string> ord(n);
    for(int i=0;i<n;i++) cin>>ord[i];
    stack<RInt> st;
    for(int i=0;i<n;i++){
        if(var.count(ord[i])){
            st.push(var[ord[i]]);
        }
        else if(ord[i]=="+"){
            RInt b=st.top(); st.pop();
            RInt a=st.top(); st.pop();
            RInt res;
            fill(res.begin(),res.end(),0);
            for(int i=0;i<256;i++){
                for(int j=0;j<256;j++){
                    if(a[i] && b[j]){
                        res[(i+j)%256]=1;
                    }
                }
            }
            st.push(res);
        }
        else if(ord[i]=="-"){
            RInt b=st.top(); st.pop();
            RInt a=st.top(); st.pop();
            RInt res;
            fill(res.begin(),res.end(),0);
            for(int i=0;i<256;i++){
                for(int j=0;j<256;j++){
                    if(a[i] && b[j]){
                        res[(i+256-j)%256]=1;
                    }
                }
            }
            st.push(res);
        }
        else if(ord[i]=="*"){
            RInt b=st.top(); st.pop();
            RInt a=st.top(); st.pop();
            RInt res;
            fill(res.begin(),res.end(),0);
            for(int i=0;i<256;i++){
                for(int j=0;j<256;j++){
                    if(a[i] && b[j]){
                        res[(i*j)%256]=1;
                    }
                }
            }
            st.push(res);
        }
        else if(ord[i]=="/"){
            RInt b=st.top(); st.pop();
            RInt a=st.top(); st.pop();
            if(b[0]){
                cout<<"error"<<endl;
                return 0;
            }
            RInt res;
            fill(res.begin(),res.end(),0);
            for(int i=0;i<256;i++){
                for(int j=0;j<256;j++){
                    if(a[i] && b[j]){
                        res[(i/j)%256]=1;
                    }
                }
            }
            st.push(res);
        }
        else{
            RInt tmp;
            fill(tmp.begin(),tmp.end(),0);
            tmp[stoi(ord[i])]=true;
            st.push(tmp);
        }
    }
    cout<<"correct"<<endl;
    return 0;
}


Measured memory_bytes: 3232
n = gets.chomp.to_i
a_arr = n.times.map{gets.to_i}

max = 0
max_i = -1
a_arr.each_with_index do |a, i|
  if a > max then
    max = a
    max_i = i
  end
end

second = 0
a_arr.each_with_index do |a, i|
  if a > second && i != max_i then
    second = a
  end
end

(0..a_arr.length-1).each do |i|
  if max_i == i then
    puts second
  else
    puts max
  end
end


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

long long card[2010];

int main()
{
    long long n,z,w;
    cin >> n >> z >> w;
    for(int i = 0; i < n; ++i)
        cin >> card[i];
    long long res = abs(card[n-1]-w);
    if(n > 1) res = max(res,abs(card[n-1]-card[n-2]));
    cout << res << endl;
    return 0;
}


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

int main() {
	int w, n, a, b;

	cin >> w >> n;
	vector<int> hlines(w);
	for (int i = 0; i < w; ++i) {
		hlines.at(i) = i + 1;
	}

	for (int i = 0; i < n; ++i) {
		cin >> a;
		cin.ignore();
		cin >> b;
		--a, --b;
		swap(hlines.at(a), hlines.at(b));
	}
	for (int i = 0; i < w; ++i) {
		cout << hlines.at(i) << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
# -*- coding: utf-8 -*-

from queue import Queue

h,w = map(int,input().split())
black, white = 0,0
s = [[0] * w for _ in range(h)]
for i in range(h):
    s[i] = list(input())
    for j in range(w):
        if s[i][j] == ".":
            white += 1
        else:
            black += 1

def bfs():
    global ans,checked
    while not que.empty():
        xy = que.get()
        if xy[0] == w - 1 and xy[1] == h - 1:
            ans = checked[xy[1]][xy[0]]
            return
        for i in range(-1,2):
            for j in range(-1,2):
                if i == j or i == -j:
                    continue
                if 0 <= xy[0] + i < w and 0 <= xy[1] + j < h:
                    if checked[xy[1] + j][xy[0] + i] == -1 and s[xy[1] + j][xy[0] + i] == ".":
                        checked[xy[1] + j][xy[0] + i] = checked[xy[1]][xy[0]] + 1
                        que.put([xy[0] + i,xy[1] + j])

que = Queue()
ans = -1
checked = [[-1] * w for _ in range(h)]
checked[0][0] = 0
que.put([0,0])

bfs()
if ans != -1:
    print(white - ans - 1)
else:
    print(-1)


Measured memory_bytes: 4076
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
four=0
two=[]
numbers=Counter(A)
for key,value in numbers.items():
    if value>=4:
        four=max(four,key**2)
    if value>=2:
        two.append(key)
sorted_two=sorted(two)
if four==0 and len(sorted_two)<=1:
    print(0)
else:
    print(max(four,sorted_two[-1]*sorted_two[-2]))
    

Measured memory_bytes: 101388
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[200010];

int main() {
	ll n, x;
	cin >> n >> x;
	if (x == 1 || x == 2 * n - 1) {
		cout << "No" << endl;
		return 0;
	}
	clr(d, -1);
	d[n - 1] = x;
	d[n - 2] = 1;
	d[n] = 2 * n - 1;
	int index = 2;
	rep(i, 0, 2 * n - 1) {
		if (index == x)index++;
		if (d[i] == -1) {
			d[i] = index;
			index++;
		}
	}
	cout << "Yes" << endl;
	rep(i, 0, 2 * n - 1) {
		cout << d[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define  fo(i,a,b) for(ll i=a;i<b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define err() cout<<"----------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589
void solve()
{
    ll n;
    cin>>n;
    vector<pair<string,ll>> v;
    v.pb(MP("AC",0));
    v.pb(MP("WA",0));
    v.pb(MP("TLE",0));
    v.pb(MP("RE",0));
    string temp;
    fo(i,0,n)
    {
        cin>>temp;
        if(temp=="AC") v[0].S++;
        else if(temp=="WA") v[1].S++;
        else if(temp=="TLE") v[2].S++;
        else v[3].S++;
    }
    fo(i,0,4)
    {
        cout<<v[i].F<<" x "<<v[i].S<<endl;
    }
}
int main()
{

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
//  clock_t time_req;
//  time_req = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

// time_req = clock()-time_req;
//  cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;

    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
包除原理
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<998244353> mint;

ll n,a[310],sum=0;
mint dp[90010]={},dp2[90010]={},zenbu=1,ans=0,ue=0,mannaka=0;

void init(){
	cin>>n;
	rep(i,n)cin>>a[i];
	dp[0]=1;
	rep(i,n)sum+=a[i];
	rep(i,n)zenbu*=3;
	cerr<<"初期化終了"<<endl;
}

int main(void){
	init();
	rep(i,n){
		reg(j,0,sum)dp2[j]=0;
		reg(j,0,sum){
			dp2[j] += dp[j]*2;//残りの2つに置く
			if(j+a[i]<=sum)dp2[j+a[i]] += dp[j];//Rに置く
		}
		reg(j,0,sum)dp[j]=dp2[j];
	}
	reg(i,(sum+1)/2,sum)ue += dp[i];
	reg(j,0,sum)dp[j]=0;
	dp[0]=1;
	rep(i,n){
		reg(j,0,sum)dp2[j]=0;
		reg(j,0,sum){
			dp2[j] += dp[j];//Bに置く
			if(j+a[i]<=sum)dp2[j+a[i]] += dp[j];//Rに置く
		}
		reg(j,0,sum)dp[j]=dp2[j];
	}
	if(sum%2==0)mannaka=dp[sum/2];
	ans=zenbu-ue*3+mannaka*3;
	cout<<ans.get()<<endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
int32_t main()
{	
	Fast_IO
	#ifdef __WIN32 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w",stdout);
	#endif
	int n;cin>>n;
	int maxcap;cin>>maxcap;
	vector<int> weights(n);
	vector<int> values(n);
	int sumv=0;
	for(int i=0;i<n;i++){
		cin>>weights[i]>>values[i];
		// sumv+=values[i];
	}
	//dp[i] - max value for weight exactly i 
	vector<int> dp(maxcap+1,0);
	for(int i=0;i<n;i++){
		for(int j=maxcap-weights[i];j>=0;j--){
			dp[j+weights[i]]=max(dp[j+weights[i]],dp[j]+values[i]);
		}
	}	
	int ans=0;
	for(int i=0;i<=maxcap;i++){
		ans=max(ans,dp[i]);
	}
	cout<<ans;


}

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

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

            /* code */
        }
        for (size_t j = 0; j < m; j++)
        {
            a[j] = (a[j] & aa[j]);
        }
    }
    int ans=0;
    for (size_t i = 0; i < m; i++)
    {
        ans += a[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20

N = int(input())
S = input()
prev = "?"
ans = 0
for c in S:
    if c != prev:
        ans += 1
        prev = c
print(ans)


Measured memory_bytes: 7312
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define zero(x) (fabs(x)<eps)
#define pi acos(-1.0)
#define f1 first
#define f2 second
#define CLR(x,y) memset(x,y,sizeof(x))
using namespace std;
#define fr(i,x,y) for(int i=x;i<=y;i++)
typedef long long ll;
typedef pair <int, int> PII;
template<typename X> inline bool minimize(X&p,X q){if(p<=q)return 0;p=q;return 1;}
template<typename X> inline bool maximize(X&p,X q){if(p>=q)return 0;p=q;return 1;}
const ll inf=1000000000000;
struct node{
    int x,y;
    bool operator<(const node&oth )const{
        return x<oth.x;
    }
};//a[105],b[105];
#define N 200005
int n;
int a[N];

void doit() {
    scanf("%d",&n);
    ll x=0;
    fr(i,1,n){
        scanf("%d",&a[i]);
        x+=a[i];
    }

    ll y=0,ans=-1,tmp;
    fr(i,1,n-1) {
        x-=a[i];
        y+=a[i];
        tmp=abs(y-x);
        if (tmp<ans|| ans==-1) ans=tmp;
    }
    printf("%lld\n",ans);
}

int main() {
    doit();

}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b;
  cin >> a >> b;
  REP(i, 1500){
    int c = i * 0.08;
    int d = i * 0.1;
    if(a == c && b == d){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	ll a, b, k;
	cin >> a >> b >> k;
	ll c = min(a, k);
	a -= c;
	k -= c;
	c = min(b, k);
	b -= c;
	cout << a << ' ' << b << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition) cout << "Yes" << '\n'; else{ cout << "No" << '\n'; }
#define YES(condition) if(condition) cout << "YES" << '\n'; else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition) cout << "yes" << '\n'; else{ cout << "no" << '\n'; }




int main() {
    ll n, a, b;
    cin >> n;
    if(n & 1){
        cout << "Hello World" << endl;
    }
    else{
        cin >> a >> b;
        cout << a + b << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int X,Y;
  cin >> X >> Y;
  
  if(Y%2==1){
    cout << "No" << endl;
  }
  else if(Y>4*X || Y<2*X){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}


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

int main(){
    int X;
    cin >> X;
        if(X == 3){
            cout << "YES" << endl;
        }
        else if(X == 5){
            cout << "YES" << endl;
        }
        else if(X == 7){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)









template <typename T>
class dijkstra {
private:
    using P = pair<T, int>;
    struct edge{
        int to;
        T cost;
    };
    int n;
    vector<vector<edge>> g;
    vector<T> dist;
    
public:
    dijkstra(int n) : n(n), g(n), dist(n, INF){}
    
    void add_edge(int v1, int v2, T cost){
        g[v1].push_back({v2, cost});
    }
    
    void run(int s){
        priority_queue<P, vector<P>, greater<P>> que;
    
        dist[s] = 0;
        que.push({0, s});
        
        while(!que.empty()){
            P p = que.top(); que.pop();
            int d = p.first;
            int now = p.second;
            if(dist[now] < d) continue;
            for(auto& e : g[now]){
                if(dist[e.to] > dist[now] + e.cost){
                    dist[e.to] = dist[now] + e.cost;
                    que.push({dist[e.to], e.to});
                }
            }
        }
    }
    
    T get_distance(int v){
        return dist[v];
    }
};




int main(){
    ll sx, sy, gx, gy, n;
    cin >> sx >> sy >> gx >> gy >> n;
    
    vector<ll> x(n), y(n), z(n);
    REP(i, n){
        cin >> x[i] >> y[i] >> z[i];
    }
    
    dijkstra<double> dik(n + 2);
    
    dik.add_edge(0, n + 1, sqrt(pow(gx - sx, 2) + pow(gy - sy, 2)));
    REP(i, n){
        dik.add_edge(0, i + 1, max(sqrt(pow(x[i] - sx, 2) + pow(y[i] - sy, 2)) - z[i], 0.0));
        dik.add_edge(i + 1, 0, max(sqrt(pow(x[i] - sx, 2) + pow(y[i] - sy, 2)) - z[i], 0.0));
        dik.add_edge(n + 1, i + 1, max(sqrt(pow(x[i] - gx, 2) + pow(y[i] - gy, 2)) - z[i], 0.0));
        dik.add_edge(i + 1, n + 1, max(sqrt(pow(x[i] - gx, 2) + pow(y[i] - gy, 2)) - z[i], 0.0));
    }
    REP(i, n - 1){
        for(int j = i + 1; j < n; j++){
            dik.add_edge(i + 1, j + 1, max(sqrt(pow(x[j] - x[i], 2) + pow(y[j] - y[i], 2)) - z[i] - z[j], 0.0));
            dik.add_edge(j + 1, i + 1, max(sqrt(pow(x[j] - x[i], 2) + pow(y[j] - y[i], 2)) - z[i] - z[j], 0.0));
        }
    }
    
    dik.run(0);
    
    printf("%.10lf\n", dik.get_distance(n + 1));
}

Measured memory_bytes: 21616
#include <iostream>
#include <algorithm>
#include <vector>
typedef std::vector<int> TList;

TList Input()
{
    int Count;
    std::cin >> Count;
    TList List(Count);
    for(int i = 0; i < Count; ++i){
        std::cin >> List[i];
    }
    return List;
}
int Count(const TList& S, const TList& T)
{
    int Sum = 0;
    for(TList::const_iterator It = T.begin(); It != T.end(); ++It){
        Sum += std::find(S.begin(), S.end(), *It) != S.end() ? 1 : 0;
    }
    return Sum;
}
int main()
{
    TList S = Input();
    TList T = Input();
    std::cout << Count(S, T) << std::endl;
}

Measured memory_bytes: 1232
H,W=map(int,input().split())
s=[]
for _ in range(H):
    s.append(list(input()))

inf=float("inf")
ans=[[inf]*W for _ in range(H)]

if s[0][0]==".":
    ans[0][0]=0
else:
    ans[0][0]=1

for i in range(H):
    for j in range(W):
        if j!=W-1:
            if s[i][j]=="." and s[i][j+1]=="#":
                ans[i][j+1]=min(ans[i][j]+1,ans[i][j+1])
            else:
                ans[i][j+1]=min(ans[i][j],ans[i][j+1])
        if i!=H-1:
            if s[i][j]=="." and s[i+1][j]=="#":
                ans[i+1][j]=min(ans[i][j]+1,ans[i+1][j])
            else:
                ans[i+1][j]=min(ans[i][j],ans[i+1][j]) 

print(ans[H-1][W-1])


Measured memory_bytes: 9312
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#include <cstdint>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

int main(){
    long n;
    scanf("%ld", &n);
    std::vector<long> l(n);
    for(int i = 0; i < n ; i++){
        std::cin >> l[i];
    }
    std::sort(l.begin(), l.end());
    long ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && l[i] + l[j] > l[k]){
                    ans++;
                }
            }
        }
    }
    printf("%ld\n", ans);
}


Measured memory_bytes: 3784
# input
K, N = map(int, input().split())
A = list(map(int, input().split()))

# process
A.sort()

maxa = 0
for i in range(1, N):
    maxa = max(maxa, A[i]-A[i-1])

maxa = max(maxa, A[0]+K-A[N-1])

# output
print(K-maxa)


Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  ll n,k;
  cin >> n >> k;
  ll ans=k;
  rep(i,n-1)ans*=(k-1);
  cout << ans << endl;
}

Measured memory_bytes: 256
s = list(input())
n = len(s)
if s[-1] == "1":
    print(-1)
    exit()
if s[:-1] != s[:-1][::-1]:
    print(-1)
    exit()
if s[0] == "0":
    print(-1)
    exit()

before = -1
for i in range(n // 2):
    if s[i] == "1":
        num = i - before
        for j in range(num):
            print(before+2, i+2-j)
        before = i

for j in range(n-2-before):
    print(before+2, before+3+j)







Measured memory_bytes: 6316
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  double p = 0.0;
  for (int i = 1; i <= N; i++) {
    if (i >= K) {
      p += 1 / double(N);
      continue;
    }
    //cout << ceil(log2(double(K) / i)) << endl;
    p += 1 / double(N) * pow(0.5, ceil(log2(double(K) / i)));
  }
  cout << setprecision(10) << p << endl;
  return 0;
}

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

int main() {
  int N, M;
  cin>> N >> M;
  //優先度付きキュー
  priority_queue<pair<int,int>> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push(make_pair(a, 1)); //A初期はそれぞれ1枚ずつ
  }
  for (int i = 0; i < M; i++) {
    int B, C;
    cin >> B >> C;
    A.push(make_pair(C, B)); //CはB枚ある
  }
  
  ll sum = 0;
  while(N > 0) {
    pair<int, int> a = A.top();
    A.pop();
    sum += a.first;
    a.second--;
    if (a.second > 0) {
      A.push(a);
    }
    N--;
  }
  cout << sum << endl;
}

    
  
  

Measured memory_bytes: 2420