akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  1000000007
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

int n,m,a[200005];

int main()
{
    sf(n);sf(m);
    int k=0;
    for(int i=0;i<=n;i++)
    {
        int x = i*2+(n-i)*4;
        if(x==m)k=1;
    }
    if(k==1)pf("Yes\n");
    else pf("No\n");
}


Measured memory_bytes: 3764
// 価値に対して重みを最小化するナップサック
#include<iostream>
using namespace std;

typedef long long ll;
ll dp[101][10001] = {};

const ll INF = 1ll<<60;

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

    for(int i = 0; i < 101; i++){
        for(int j = 0; j < 10001; j++){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    int v, w;
    for(int i = 0; i < n; i++){
        cin >> v >> w;
        for(int j = 0; j < 10001-v; j++){
            if(dp[i][j] != INF){
                dp[i+1][j+v] = min(dp[i+1][j+v], dp[i][j]+w);
                dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            }
        }
    }

    for(int j = 10000; j >= 0; j--){
        for(int i = 0; i <= 100; i++){
            if(dp[i][j] <= W){
                cout << j << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 10976
n,a=int(input()),list(map(int,input().split()))
g=0
from math import gcd
for i in a:g=gcd(i,g)
if g!=1:print("not coprime")
else:
    from collections import defaultdict
    memo=defaultdict(int)
    for i in a:
        for p in range(2,int(i**.5)+1):
            if i%p==0:
                while i%p==0:i//=p
                if memo[p]:
                    print("setwise coprime");exit()
                memo[p]+=1
        if i!=1:
            if memo[i]:print("setwise coprime");exit()
            memo[i]+=1
    print("pairwise coprime")

Measured memory_bytes: 191912
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int max = 0;
    int x = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == 'I') x++;
        else if(S[i] == 'D') x--;

        if(max < x) max = x;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int K,N;
int A[200010];
signed main(){
    scanf("%lld %lld",&K,&N);
    int ans=K;
    rep(i,N){
        scanf("%lld",&A[i]);
        if(i>0)ans=min(ans,K-(A[i]-A[i-1]));
    }
    ans=min(ans,K-(K-A[N-1]+A[0]));
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1664
N=int(input())
start=0
end=0
r=0
cnt=0
for i in range(N):
    s=input()
    cnt+=s.count('AB')
    if s[0] == 'B':
        start+=1
    if s[-1] == 'A':
        end+=1
    if s[0] == 'B' and s[-1] == 'A':
        r+=1
if start == end and start == r and end > 0:
    cnt -=1
print(cnt+min(start,end))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll n, m, a[110000], b[110000], ans[110000], na = 0;

UnionFind u(210000);
int main() {
	cin >> n >> m;
	REP(i, m) cin >> a[i] >> b[i];
	REPR(i, m - 1) {
		ll x = a[i], y = b[i];
		if (!u.findSet(x, y)) {
			ans[i] = u.size(x) * u.size(y);
		}
		u.unionSet(x, y);
	}
	REP(i, m) {
		na += ans[i];
		cout << na << endl;
	}
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

int main(){

    ll n, m; cin >> n >> m;
    vector<ll> p(n+1, 0);
    p[0] = 1;
    p[1] = 1;
    ll in;
    rep(i, m){
        cin >> in;
        p[in] = -1;
    }

    rep2(i, 2, n+1){
        if(p[i] == -1) continue;
        p[i] = ((p[i-1] == -1) ? 0 : p[i-1]) + ((p[i-2] == -1) ? 0 : p[i-2]);
        p[i] %= 1000000007;
    }

    cout << p[n] << endl;

    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

int main() {
    string s, ans;
    cin >> s;
    for (int bit = 0; bit < (1 << 3); bit++) {
        int t = s[0] - '0';
        ans = s[0];
        for (int i = 2; i >= 0; i--) {
            if (bit & (1 << i)) {
                t += s[2-i+1] - '0';
                ans = ans + '+' + s[2-i+1];
            } else {
                t -= s[2-i+1] - '0';
                ans = ans + '-' + s[2-i+1];
            }
        }
        if (t == 7) {
            cout << ans << "=7\n";
            break;
        }
    }
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int N,K;
int a[5000];

//a_nを除いたカードで数が作れるか
bool jud(int n){
  bool dp[5001];
  fill(dp,dp+5001,false);
  dp[0] = true;
  for(int i=0;i<N;i++){
    if(i == n) continue;

    for(int j=K;j>=0;j--){
      if(dp[j] && j + a[i] <= K){
        dp[j + a[i]] = true;
      }
    }
  }

  for(int i=max(0,K-a[n]);i<K;i++){
    if(dp[i]){
      return true;
    }
  }

  return false;
}

int bs(int a, int b){
  int p = (a + b) / 2;
  bool j = jud(p);

  if(a == b){
    if(a == 0 && j) return -1;
    else if(a == N-1 && j == 0) return N-1;
    else if(j) return a-1;
    else if(!j) return a;
  }
  else {
    if(j){
      return bs(a,p);
    } else {
      return bs(p+1,b);
    }
  }
}

//======================================================
int main(){
  cin >> N >> K;
  for(int i=0;i<N;i++) cin >> a[i];
  sort(a,a+N);

  //一番右の不必要
  cout << bs(0,N-1) + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int isprime(int n)
{
int check=1;
for(int i=2;i<n/2;i++)
{
if(n%i==0)
	{check=0;break;}
else continue;}
return check;
}
int main()
{
int n,k;cin>>n>>k;
string s;
cin>>s;
if(s[k-1]=='A')
	s[k-1]='a';
else if(s[k-1]=='B')
	s[k-1]='b';
else s[k-1]='c';
cout<<s;
return 0;
}


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

#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i,n) {
        cin >> s.at(i) >> t.at(i);
    }
    string x;
    cin >> x;


    int index,ans;
    rep(i,n){ 
        if(x.compare(s.at(i))==0){
            index=i;
        }
    }

    for(int i=index+1; i<n; i++){
        ans+=t.at(i);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
w = []
v = []
for _ in range(N):
    x, y = map(int, input().split())
    w.append(x)
    v.append(y)
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(1, N+1):
    for j in range(1, W+1):
        dp[i][j] = max(dp[i][j], dp[i-1][j])
        if j - w[i-1] < 0:
            continue
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1])
# print(*dp, sep='\n')
print(dp[N][W])

Measured memory_bytes: 171784
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int N;
	ll K;
	scanf("%d %lld", &N, &K);
	vector<pair<ll, ll> > data(N);
	rep(i,N) {
		ll A, B;
		scanf("%lld %lld", &A, &B);
		data[i].first = A;
		data[i].second = B;
	}
	sort(data.begin(), data.end());
	
	ll mask = 1;
	while (mask <= K) mask *= 2;
	mask /= 2;
	ll ans = 0;
	rep(i,N)if(data[i].first < mask) ans += data[i].second;
	
	for (; mask > 0; mask /= 2) if (K & mask) {
		// not adopt
		ll sum = 0;
		rep(i, N) {
			if (data[i].first < mask) sum += data[i].second;
			else data[i].first ^= mask;
		}
		ans = max(ans, sum);
		
		// adopt goes on
		K ^= mask;
	}
	ll sum = 0;
	rep(i, N) if (data[i].first == 0) sum += data[i].second;
	ans = max(ans, sum);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

//エラトステネスの篩
int prime[MAX]; //i番目の素数
bool is_prime[MAX]; //素数かどうか
bool similar[MAX];
int sum[MAX];

void sieve(int n) {
    int p = 0;
    for (int i = 0; i <= n; i++) {
        is_prime[i] = true;
    }
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    for(int i = 0; i<=n; i++) similar[i] = false;
    for(int i = 3; i<=n; i+=2){
      if(is_prime[i] and is_prime[(i+1)/2]) similar[i] = true;
    }
    for(int i = 3; i<=n; i++){
      if(similar[i]) sum[i] = sum[i-1] + 1;
      else sum[i] = sum[i-1];
    }
}


int main(){
  ll Q; cin>>Q;
  sieve(MAX);
  while(Q--){
    int a,b; cin>>a>>b;
    cout<<sum[b] - sum[a-1]<<endl;
  }
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main(){
    cout<<fixed<<setprecision(10);
    int N,M;
    cin>>N>>M;
    if(N<=M){
        cout<<"Yes";
    }else{
        cout<<"No";

    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s.substr(0, 4) == "YAKI") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;


class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int[] unko=new int[4];
		for(int i=0; i<4; i++) {
			unko[i]=sc.nextInt();
		}
		Arrays.sort(unko);
		if(unko[0]==1 && unko[1]==4 && unko[2]==7 && unko[3]==9) {
			pl("YES");
		}
		else {
			pl("NO");
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 21076
#include <iostream>
using namespace std;
int main()
{
 int i,h,n;
 long long int s;
 s=0;
 cin >> h >> n;
 int a[n];
 for(i=0;i<n;i++)
 {
  cin >> a[i];
  s+=a[i];
 }
 if(s>=h)
 cout << "Yes";
 else
 cout << "No";
 return 0;
}

Measured memory_bytes: 640
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;

int gcd(int a, int b)
{
    if (a%b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a%b));
    }
}

int main(int argc, const char * argv[]) {

    int k;
    long long ans = 0;
    
    cin >> k;
    
    for(int i=1; i<=k; i++)
    {
        for(int j=1; j<=k; j++)
        {
            for(int l=1; l<=k; l++)
            {
                ans += gcd(i, gcd(j, l));
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
int main()
{
    char str[101],answer[101];//刚开始的时候的输入存在str数组里，输出存在answer数组里。
    gets(str);
    int lens=strlen(str),i,lena=0;//lena是answer数组的长度，目前一个字符都没插，长度为0
    for(i=0;i<lens;i++)
        switch(str[i])
        {
            case '0':answer[lena]='0';lena++;break;//是0的情况，在空串的右边插入0
            case '1':answer[lena]='1';lena++;break;//同样
            case 'B':if(lena!=0) lena--;break;//是退格键的时候，先判断现在是不是空串，如果不是，就退一格
        }
    for(i=0;i<lena;i++)
        printf("%c",answer[i]);//输出
    printf("\n");//注意换行
}

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

const int N = 2e5 + 10;
int n, a[N];

int main() {
    cin >> n;
    rep(i, 1, n) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    rep(i, 2, n) if (a[i] == a[i - 1]) { puts("NO"); return 0; }
    puts("YES");
    return 0;
}


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

int Y, M, D;

int calc(int y, int m, int d) {
    int res = 0;
    for (int i = 1; i < y; i++) {
        if (i % 3 == 0) res += 10 * 20;
        else res += 5 * 20 + 5 * 19;
    }
    if (y % 3 == 0) {
        res += (m - 1) * 20;
    } else {
        for (int i = 1; i < m; i++) {
            if (i % 2 == 1) res += 20;
            else res += 19;
        }
    }
    res += d;
    return res;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> Y >> M >> D;
        cout << calc(1000, 1, 1) - calc(Y, M, D) << endl;
    }
}


Measured memory_bytes: 3104
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    vector<string> day{"SAT","FRI","THU","WED","TUE","MON","SUN"};
    int ans=0;
    string s;cin >> s;
    for(int i = 0;i < 7;i++)
    {
        if(day[i] == s)
        {
            ans = i + 1;
        }
    }
    cout << ans;

}

Measured memory_bytes: 764
def main():
	a,b = map(int,input().split())

	if (a**2 - b**2) / (2*a-2*b) == (a**2 - b**2)//(2*a-2*b):
		print((a**2 - b**2)//(2*a-2*b))
	else:
		print("IMPOSSIBLE")

 
if __name__ == '__main__':
	main()

Measured memory_bytes: 38512
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	vector<int>p(n);
	rep(i,n)cin>>p[i];
	int sum=0;
	for(int i=1;i<n-1;i++){
		if((p[i]-p[i+1])*(p[i]-p[i-1])<0)sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

void countingsort(int a[], int b[], int k, int n) {
  int i, j;
  int c[k+1];
  for (i = 0; i <= k; i++) 
    c[i] = 0;
  for (i = 0; i < n; i++) 
    c[a[i]]++;
  for (i = 1; i <= k; i++)
    c[i] += c[i-1];
  for (i = n-1; i >= 0; i--) {
    b[c[a[i]]-1] = a[i];
    c[a[i]]--;
  }
}
    
int main(void)
{
  int n, i;
  int *a, *b;
  int max = 0;
  scanf("%d", &n);
  a = malloc(sizeof(int) * n);
  b = malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > max)
      max = a[i];
  }
  countingsort(a, b, max, n);
  for (i = 0; i < n-1; i++)
    printf("%d ", b[i]);
  printf("%d\n", b[n-1]);
  return 0;
}



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

#define MAX_N 100001
#define MOD 1000000007


void solve(long long N, long long M){
	long long res = 0;
	if (N == M-1 || N-1 == M) {
		res = 1;
		for (long long i=1; i<=N; i++) res = res*i%MOD;
		for (long long i=1; i<=M; i++) res = res*i%MOD;
	}
	if (N == M) {
		res = 1;
		for (long long i=1; i<=N; i++) res = res*i%MOD;
		for (long long i=1; i<=M; i++) res = res*i%MOD;
		res = res*2%MOD;
	}
	printf("%lld\n", res);
}

int main(){
	long long M;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&M);
	solve(N, M);
	return 0;
}


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

int main()
{
  int n;
  string s;

  scanf("%d",&n);
  cin >> s;

  int x=0;
  int max=0;
  
  for (int i=0;i<n;i++) {
    if (s[i]=='I') {
      x++;
    } else {
      x--;
    }
    if (x>max) {
      max=x;
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

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


Measured memory_bytes: 3584
#!/usr/bin/env python3
import collections as cl
import sys

MOD = 10 ** 9 + 7


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, M = MI()
    isbroken = [False] * (N + 1)
    for i in range(M):
        a = II()
        isbroken[a] = True

    steps = [0] * (N + 1)

    steps[0] = 1
    if not isbroken[1]:
        steps[1] = 1
    for i in range(2, N + 1):
        if isbroken[i]:
            continue
        steps[i] = steps[i - 1] + steps[i - 2]
        steps[i] %= MOD
    print(steps[-1])


main()


Measured memory_bytes: 75336
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = Integer.parseInt(sc.next());
		int s = Integer.parseInt(sc.next());
		int ans = 0;
		for (int x = 0; x <= k; x++)
			for (int y = 0; y <= k; y++)
				if (s - x - y >= 0 && s - x - y <= k)
					ans++;
		System.out.println(ans);
	}
}

Measured memory_bytes: 23636
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second


main(){
  int n;
  cin>>n;
  while(n--){
    map<int,int> masu[9],tate[9],yoko[9];
    int puz[9][9];
    rep(i,9)rep(j,9){
      cin>>puz[i][j];
      masu[i/3*3+j/3][puz[i][j]]++;
      tate[i][puz[i][j]]++;
      yoko[j][puz[i][j]]++;
    }

    rep(i,9){
      rep(j,9){
        if(masu[i/3*3+j/3][puz[i][j]]>1 || tate[i][puz[i][j]]>1 || yoko[j][puz[i][j]]>1)cout<<"*";
        else cout<<" ";
        cout<<puz[i][j];
      }
      cout<<endl;
    }
    if(n)cout<<endl;
  }
}

Measured memory_bytes: 0
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = pow(10, 10)
for i in range(N-K+1):
    temp_l = abs(x[i]) + abs(x[i]-x[i+K-1])
    temp_r = abs(x[i+K-1]) + abs(x[i]-x[i+K-1])
    ans = min(ans, temp_l, temp_r)
print(ans)


Measured memory_bytes: 14252
#include <cstdio>
#include <cstring>

#define MOD (10000)

using namespace std;

int sum(int *p)
{
	return (p[0] + p[1]);
}

int main(void)
{
	int n, k;
	static int dp[100][3][2];
	int done[100];
	
	scanf("%d %d", &n, &k);
	
	memset(done, -1, sizeof(done));
	for (int i = 0; i < k; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		done[--a] = --b;
	}
	
	for (int i = 0; i < 3; i++){
		if (~done[0]) dp[0][done[0]][0] = 1;
		else dp[0][i][0] = 1;
	}
	
	for (int i = 1; i < n; i++){
		for (int j = 0; j < 3; j++){
			if (~done[i]){
				j = done[i];
				dp[i][j][0] = (sum(dp[i - 1][(j + 1) % 3]) + sum(dp[i - 1][(j + 2) % 3])) % MOD;
				dp[i][j][1] = dp[i - 1][j][0] % MOD;
				break;
			}
			else {
				dp[i][j][0] = (sum(dp[i - 1][(j + 1) % 3]) + sum(dp[i - 1][(j + 2) % 3])) % MOD;
				dp[i][j][1] = dp[i - 1][j][0] % MOD;
			}
		}
	}
	
	int s = 0;
	for (int i = 0; i < 3; i++){
		s += sum(dp[n - 1][i]);
	}
	
	printf("%d\n", s % MOD);
	
	return (0);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n,ans=0;
	cin >> n;
	vll a(n);
	rep(i,n) cin >> a[i];
	rep(i,n){
		if(a[i]==i+1){
			swap(a[i],(i==n-1?a[i-1]:a[i+1]));
			ans++;
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int s = 0;
    rep(i, n) {
        cin >> a[i];
        s ^= a[i];
    }
    vector<int> b(n);
    rep(i, n) {
        b[i] = s ^ a[i];
    }
    sort(ALL(a));
    sort(ALL(b));
    if(a == b) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int V, E;
    cin >> V >> E;
    struct edge { int to, weight;};
    auto g = make_vec<edge>(V, 0);
    rep(i, E) {
        int s, t, d;
        cin >> s >> t >> d;
        g[s].push_back({t, d});
    }
    auto dp = make_vec<int>(1 << V, V);
    const int inf = 1001001001;
    fill_v<int>(dp, inf);
    dp[0][0] = 0;
    rep(bit, 1 << V) {
        rep(i, V) {
            for (edge& e : g[i]) {
                if (bit >> e.to & 1) continue;
                chmin(dp[bit | (1 << e.to)][e.to], dp[bit][i] + e.weight);
            }
        }
    }
    int ans = dp[(1 << V) - 1][0];
    cout << (ans == inf ? -1 : ans) << endl;
}



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

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"
#define MAXN 200002

int n;
int a[MAXN];

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
		--a[i];
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] == i) {
			if (i + 1 < n)
				swap(a[i + 1], a[i]);
			else
				swap(a[i - 1], a[i]);
			++ans;
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string i;
    getline(cin,i);
    
    if(i=="SUN"){
    cout<<7;}
    else if(i=="MON"){
    cout<<6;}
    else if(i=="TUE"){
    cout<<5;}
    else if(i=="WED"){
    cout<<4;}
    else if(i=="THU"){
    cout<<3;}
    else if(i=="FRI"){
    cout<<2;}
    else if(i=="SAT"){
    cout<<1;}
    
    return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

h,a = inpm()

for i in range(1,10001):
    h -= a
    if  h <= 0:
        print(i)
        break

Measured memory_bytes: 31288
using System;
using System.Linq;

namespace AOJ.Volume2
{
    public class LeadTo6174
    {
        public static int Main()
        {
            while (true)
            {
                var input = Console.ReadLine();
                if (input == "0000") { break; }

                if (input[0] == input[1] && input[1] == input[2] && input[2] == input[3])
                {
                    // ????????°??????????????§????????´??????"NA"
                    Console.WriteLine("NA");
                    continue;
                }

                int answer = 0;
                while(input != "6174")
                {
                    answer++;
                    var s_ar = new char[4];
                    s_ar[0] = input[0];
                    s_ar[1] = input[1];
                    s_ar[2] = input[2];
                    s_ar[3] = input[3];
                    Array.Sort(s_ar);

                    var l_ar = new char[4];
                    l_ar[0] = s_ar[3];
                    l_ar[1] = s_ar[2];
                    l_ar[2] = s_ar[1];
                    l_ar[3] = s_ar[0];

                    string small = "";
                    string large = "";
                    for (int i = 0; i < 4; i++)
                    {
                        small += s_ar[i];
                        large += l_ar[i];
                    }

                    input = (int.Parse(large) - int.Parse(small)).ToString().PadLeft(4, '0');
                }

                Console.WriteLine(answer);
            }
            return 0;
        }
    }
}

Measured memory_bytes: 9368
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int r = scan.nextInt(), c = scan.nextInt();
        int[][] a = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                a[i][c] += a[i][j] = scan.nextInt();
                a[r][j] += a[i][j];
                a[r][c] += a[i][j];
            }
        }
        for (int i = 0; i < r + 1; i++) {
            for (int j = 0; j < c; j++) {
                    System.out.print(a[i][j] + " ");
            }
            System.out.println(a[i][c]);
        }

    }
}

Measured memory_bytes: 44024
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    // O(N logN logN) になっちゃう
    ll N, M; cin >> N >> M;
    vector<ll> a(N), sum(N+1, 0);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end());
    rep(i, N) sum[i+1] = sum[i]+a[i];
    
    ll ok = 0; ll ng = 1e9;
    auto check = [&](ll x) {
        ll cnt = 0;
        rep(i, N) cnt += a.end() - lower_bound(a.begin(), a.end(), x-a[i]);
        return cnt;
    };
    while(ng-ok>1) {
        ll mid = (ok+ng)/2;
        (check(mid)>=M? ok:ng) = mid;
    }

    ll x = ok+1;
    ll ans = 0; ll cnt = 0;
    rep(i, N) {
        int cur = lower_bound(a.begin(), a.end(), x-a[i]) - a.begin();
        ans += sum[N]-sum[cur] + a[i]*(N-cur);
        cnt += N-cur;
    }
    if (cnt<M) ans += (M-cnt) * ok;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;

//価値v,重さw
int Knapsack(int n,int W, vector<int>& v,vector<int>& w){
    W++;
    twovec(dp,n,W);
    dp[0][w[0]] = v[0];
    FOR(i,1,n){
        if(w[i] >= W) continue;
        dp[i][w[i]] = max(v[i],dp[i-1][w[i]]);
        REP(j,W){
            if(dp[i-1][j] != 0){
                dp[i][j] = max(dp[i][j],dp[i-1][j]);
                if(j+w[i] < W){
                    dp[i][j+w[i]] = dp[i-1][j] + v[i];
                }
            }
        }
    }
    int ans = 0;
    REP(i,W){
        ans = max(ans,dp[n-1][i]);
    }
    return ans;
}

int Knapsack_big(int n,int W, vector<int>& v,vector<int>& w){
    vector<int> dp(n*100+1,W+1);
    dp[0] = 0;
    REP(i,n){
        for(int j = dp.size()-1; j >= v[i]; j--){
            if(dp[j] > dp[j-v[i]] + w[i]) dp[j] =  dp[j-v[i]] + w[i];
        }
    }
    //Debug(dp);
    for(int i = dp.size()-1;i >= 0; i--){
        if(dp[i] != W+1) return i;
    }

}

//価値v,重さw
int Knapsack_mult(int n,int W, vector<int>& v,vector<int>& w){
    W++;
    vec(dp,W);
    REP(i,n){
        if(w[i] >= W) continue;
        dp[w[i]] = max(v[i],dp[w[i]]);
        REP(j,W){
            if(j+w[i] >= W) break;
            if(dp[j] != 0){
                dp[j+w[i]] = max(dp[j] + v[i],dp[j+w[i]]);
            }
        }
        //Debug(dp);
    }
    //Debug(dp);
    int ans = 0;
    REP(i,W){
        ans = max(dp[i],ans);
    }
    return ans;
}


signed main(){
    int W;
    cin >> n >> W;
    vec(v,n);
    vec(w,n);
    REP(i,n){
        cin >> v[i] >> w[i];
    }
    print(Knapsack_big(n,W,v,w));
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<ll,ll>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

struct UnionFind {
    vector<int> par,rank,large;
    int cnt;

    void init(int N){
        rank.assign(N,0);
        large.assign(N,1);
        par.resize(N);
        cnt=N;
        for(int i= 0; i < N; i++){
            par[i]=i;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if(rank[rx]<rank[ry]) {
            par[rx]=ry;
            large[ry]+=large[rx];
            large[rx]=0;
            cnt--;
        }
        else {
            par[ry]=rx;
            large[rx]+=large[ry];
            large[ry]=0;
            if(rank[rx]==rank[ry])rank[x]++;
            cnt--;
        }
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return large[root(x)];
    }
};

int main() {
    int N,M;
    cin>>N>>M;
    UnionFind forest;
    forest.init(N);
    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin>>v[i];
    for(int i = 0; i < M; i++){
        int x,y;
        cin>>x>>y;
        forest.unite(x,y);
    }
    int cnt = forest.cnt;
    if(N<2*cnt-2) cout<<"Impossible"<<endl;
    else if(cnt ==1) cout<<0<<endl;
    else{
        ll ans = 0LL;
        map<int,int> m;
        int s = 1;
        for(int i = 0; i < N; i++){
            if(m[forest.root(i)]==0){
                m[forest.root(i)]=s;
                s++;
            }
        }
        map<int,bool> mb;
        vector<P> R(cnt,make_pair(INF,INF));
        for(ll i = 0; i < N; i++){
            chmin(R[m[forest.root(i)]-1],make_pair(v[i],i));
        }
        for(ll i = 0; i < cnt; i++) {
            ans+=R[i].first;
            mb[R[i].second]=true;
        }
        vector<P> rest(N);
        for(ll i = 0; i < N; i++){
            rest[i]=make_pair(v[i],i);
        }
        sort(rest.begin(),rest.end());
        int a = 0;
        for(int i = 0; i < N; i++){
          	if(a>=cnt-2) break;
            if(mb[rest[i].second]) continue;
            ans+=rest[i].first;
            mb[rest[i].second]=true;
          	a++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 11648
use std::io::*;
use std::str::FromStr;


fn abc(n: i32) -> String {
    let l:i32 = 25;
    for i in (0..l) {
        for j in (0..(l)) {
            if 4*i + 7*j == n {
                return "Yes".to_string()
            }
        }
    }
    return "No".to_string()
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    /*
    assert_eq!(abc(), "Yes");
    assert_eq!(abc(101), "No");
    assert_eq!(abc(999999999), "Yes");
    */
    let n: i32 = read();

    let result = abc(n);
    
    println!("{}", result);
    
}



Measured memory_bytes: 4352
package main

import (
	"fmt"
)

func main(){
	var a, b int
	var op string
	for{
		fmt.Scan(&a, &op, &b)
		if op == "+"{
			fmt.Println(a+b)
		} else if op == "-" {
			fmt.Println(a-b)
		} else if op == "*" {
			fmt.Println(a*b)
		} else if op == "/" {
			fmt.Println(a/b)
		} else {
			break
		}
	}
}


Measured memory_bytes: 1128
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
    priority_queue<int> diff;
    int K, N,get, first=0;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>K;
    cin>>N;
    cin>>first;
    int temp = first;
    for(int i = 1; i < N; i++){
        cin>>get;
        diff.push(get-temp);
        temp = get;
    }
    diff.push(abs(K-get)+abs(0-first));
    cout<<(K-diff.top())<<endl;

    return 0;
}




Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll X;
    cin>>X;
    ll ans = 0;
    ans += X/500;
    ans *= 1000;
    ll n = (X%500)/5;
    n *= 5;
    ans += n;
    cout<<ans;
    return 0;
}

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


#define loop(i,n) for(int lc=i;lc<=n;lc++)
#define tloop(tn) for(int tlc=1;tlc<=tn;tlc++)
#define loop2(i2,n2) for(int lc2=i2;lc2<=n2;lc2++)
#define bloop(n,bn) for(int blc=n;blc>=bn;blc--)
#define il() while(true)
#define pi acos(-1)
#define rad_to_deg(angl) ((180*angl)/pi)
#define ll long long
#define caseno printf("Case %d: ",tlc);

#define sfi(def_var) scanf("%d",&def_var)
#define sfii(def_var,def_var2) scanf("%d %d",&def_var,&def_var2)
#define sfll(def_var,def_var2) scanf("%lld %lld",&def_var,&def_var2)

#define sfl(def_var) scanf("%lld",&def_var)
#define sfd(def_var) scanf("%lf",&def_var)
#define sfs(def_var) scanf("%s",&def_var)

#define pfie(def_var) printf("%d\n",def_var)
#define pfi(def_var) printf("%d",def_var)
#define pfl(def_var) printf("%lld",def_var)
#define pfd(def_var) printf("%lf",def_var)
#define nl printf("\n");

int n;
int a[100010][3];
int dp[100010][3];
int find_ans(int i,int taken=1)
{
    //cout << "called for " << i << ". taken : " << 1 << endl;
    if(i==n+1)
    {
        //cout << "out of range return 0\n";
        return 0;
    }
    if(i==1)
    {
        dp[i][0]=a[i][0]+find_ans(i+1,0);
        //cout << "return to call : " << i << " taken : " << 0 << endl;
        dp[i][1]=a[i][1]+find_ans(i+1,1);
        //cout << "return to call : " << i << " taken : " << 1 << endl;
        dp[i][2]=a[i][2]+find_ans(i+1,2);
        //cout << "return to call : " << i << " taken : " << 2 << endl;

        if(dp[i][2]>dp[i][1] && dp[i][2]>dp[i][0])
        {
            return dp[i][2];
        }
        else if(dp[i][1]>dp[i][0])
        {
            return dp[i][1];
        }
        else return dp[i][0];

    }


    if(taken==0)
    {
        if(dp[i][1]==-1) dp[i][1]=a[i][1]+find_ans(i+1,1);
        //cout << "return to call : " << i << " taken : " << 1 << endl;
        if(dp[i][2]==-1) dp[i][2]=a[i][2]+find_ans(i+1,2);
        //cout << "return to call : " << i << " taken : " << 2 << endl;
        return max(dp[i][1],dp[i][2]);
    }
    if(taken==1)
    {
        if(dp[i][0]==-1) dp[i][0]=a[i][0]+find_ans(i+1,0);
        //cout << "return to call : " << i << " taken : " << 0 << endl;
        if(dp[i][2]==-1) dp[i][2]=a[i][2]+find_ans(i+1,2);
        //cout << "return to call : " << i << " taken : " << 2 << endl;
        return max(dp[i][0],dp[i][2]);
    }
    if(taken==2)
    {
        if(dp[i][1]==-1) dp[i][1]=a[i][1]+find_ans(i+1,1);
        //cout << "return to call : " << i << " taken : " << 1 << endl;
        if(dp[i][0]==-1) dp[i][0]=a[i][0]+find_ans(i+1,0);
        //cout << "return to call : " << i << " taken : " << 0 << endl;
        return max(dp[i][1],dp[i][0]);
    }

}

int main()
{
    sfi(n);
    loop(1,n)
    {
        sfii(a[lc][0],a[lc][1]);
        sfi(a[lc][2]);
        dp[lc][0]=dp[lc][1]=dp[lc][2]=-1;

    }
    pfie(find_ans(1));
}


Measured memory_bytes: 7296