akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	f := true
	for i := 0; i < n; i++ {
		a, _ := strconv.Atoi(stringLineScan())
		if a%2 == 0 {
			if a%3 != 0 && a%5 != 0 {
				f = false
				break
			}
		}
	}
	if f {
		fmt.Println("APPROVED")
	} else {
		fmt.Println("DENIED")
	}
}


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

int main (){
    int64_t A, V, B, W, T;
    string a, b, c;
    cin >> A >> V >> B >> W >> T;
    if(T*(V-W) >= abs(B-A)){
        cout << "YES" << endl;
     }else{
        cout << "NO" << endl;
        }
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

bool is_integer(double x) {
	return std::floor(x) == x;
}

int main(){
	int N, D; std::cin >> N >> D;
	std::vector<std::vector<int>> X(N, std::vector<int>(D));
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < D; ++j)
			std::cin >> X[i][j];
	int count = 0;
	for (int i = 0; i < N - 1; ++i) {
		for (int k = i + 1; k < N; ++k) {
			int total = 0;
			for (int j = 0; j < D; ++j)
				total += std::pow(X[i][j] - X[k][j], 2);
			if (is_integer(std::sqrt(total)))++count;
		}
	}
	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long
#define MOD 1000000007

using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    int sum=1;
    for(int i=0;i<N;i++){
        if(sum<K){
            sum*=2;
        }
        else{
            sum+=K;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
///*.......................Shadman Sakib Utshob............................*///

#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

#define Boost           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define pb              push_back
#define inf             1e9+8
#define mp              make_pair
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define ll              long long
#define pii             pair<ll,ll >
#define MOD             1000000007
#define fileout         freopen("output.txt","w",stdout)
#define mem(x,i)        memset(x,i,sizeof x)
#define Ones(x)         __builtin_popcount(x);
#define PI              acos(-1.0)
#define ff              first
#define ss              second
#define T               int t;cin>>t;while(t--)
#define ok              cout<<"ok"<<endl;
#define all(x)          (x).begin(),(x).end()
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define nln	            cout<<endl;

int main()
{
    Boost;

    ll i,j,n,k,x;

    cin>>n>>k;
    ll h[n+10],dp[n+10];
    mem(dp,inf);
    rep1(i,n)
    {
        cin>>h[i];
    }
    dp[1]=0;
    dp[2]=abs(h[1]-h[2]);
    if(n==2)
    {
        cout<<dp[2]<<endl;
        return 0;
    }
    //see(dp[2])
    for(i=3; i<=n; i++)
    {
        x=k;
        for(j=i-1;; j--)
        {

            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
            //see(dp[i])see(i)

            x--;
            if(x==0 || j==1)
                break;
        }

        //see(dp[i])
    }
    cout<<dp[n]<<endl;

}


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

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

  int X;
  cin >> X;

  cout << (X >= 30 ? "Yes" : "No") << endl;

  return 0;
}



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

using namespace std;

int main()
{
  string s;
  cin >> s;
  for (int i = 0; i < (int) s.size() - 1; i++)
  {
if (s[i] == 'A' && s[i + 1] == 'C')
{
cout << "Yes\n";
  return 0;
}
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
// Date: 2020-03-18

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout<<#x<<" = "<<x<<endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 51;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

LL dp[2][N][N*N];
int n, m, x[N], sum[N];

int main() {
    FIO;
    cin >> n >> m;
    rep(i, 1, n) cin >> x[i], sum[i] = sum[i-1] + x[i];
    dp[0][0][0] = 1;
    int cur = 1;
    rep(i, 1, n) {
        rep(j, 0, i) {
            rep(k, 0, sum[i]) {
                dp[cur][j][k] = dp[cur^1][j][k];
                if(j && k >= x[i]) dp[cur][j][k] += dp[cur^1][j-1][k-x[i]];
            }
        }
        cur ^= 1;
    }
    LL ans = 0;
    rep(i, 1, n) ans += dp[cur^1][i][i*m];
    cout << ans;

    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repp(i, n) for(int i = 1; i <= (int)(n); i++)
#define co(x) cout<<x<<endl
typedef long long int lint;
 
int main() {
  lint K,N,max;
  cin >> K >> N;
  vector<lint> A(N),Dis(N);
  rep(i,N){cin >> A.at(i);}
  rep(i,N-1){Dis.at(i) = A.at(i+1) - A.at(i);}
  Dis.at(N-1) = K - A.at(N-1) + A.at(0);
  
  max = *max_element(Dis.begin(),Dis.end());
  co(K - max);
}

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

int main() {
  int n;
  cin >> n;
  int sum_arr = 0;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum_arr += arr[i];
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res += arr[i] * (sum_arr - arr[i]);
  }
  cout << res / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,d,a;
vector<pair<ll,ll> > v;
vector<ll> np,qdh,ver;
void minu(ll y)
{
	ll pos,pos2,x;
	x=ver[y];
	pos=upper_bound(np.begin(),np.end(),x+2*d)-np.begin()-1;
	pos2=lower_bound(np.begin(),np.end(),x)-np.begin()-1;
	v[y].S-=(qdh[pos]-qdh[pos2])*a;
	v[y].S=max(v[y].S,(ll)0);
	return;
}
int main(){
	ll i,x,y,pos;
	cin>>n>>d>>a;
	np.push_back(-1);
	qdh.push_back(0);
	for(i=0;i<n;i++)
	{
		cin>>x>>y;
		ver.push_back(x);
		v.push_back(make_pair(x,y));
	}
	sort(ver.begin(),ver.end());
	sort(v.begin(),v.end());
	for(i=0;i<v.size();i++)
	{
		minu(i);
		pos=upper_bound(ver.begin(),ver.end(),ver[i]+2*d)-ver.begin()-1;
		np.push_back(ver[pos]);
		qdh.push_back(qdh[qdh.size()-1]+(v[i].S+a-1)/a);
	}
	cout<<qdh[qdh.size()-1]<<endl;
	return 0;
}

Measured memory_bytes: 10720
#include<stdio.h>
int main(){
	double r;
	double S=0.0,L=0.0,pi=3.14159265359;
	scanf("%lf",&r);
	S=r*r*pi;
	L=2*r*pi;
	printf("%.6lf %.6lf\n",S,L);
	return 0;
}

Measured memory_bytes: 2576
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using vl = vector<ll>;                   //   | grep -v ' .* '  1300111 ~2^20.31
using vvl = vector<vl>;                  //                    10300777 ~2^23.30
using pll = pair<ll,ll>;                 //                   100400999 ~2^26.58
using vb = vector<bool>;                 //                  1300400999 ~2^30.28
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //                 10200500333 ~2^33.25
const double eps = 1e-9;                 //                100200400777 ~2^36.54
#define sz(c) ll((c).size())             //               1200300700111 ~2^40.13
#define all(c) begin(c),end(c)           //              10200300500777 ~2^43.21
#define mp make_pair                     //             100200300400777 ~2^46.51
#define mt make_tuple                    //            1200300400600999 ~2^50.09
#define pb push_back                     //           10200300400600111 ~2^53.18
#define eb emplace_back                  //          100200300400600333 ~2^56.48
#define xx first                         //         1200300400500800999 ~2^60.06
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define FORD(i,a,b) for (int i=int(b)-1; i>=(a); i--)

template<class T>
ll qp(T & a) {
	cin >> a;
}
template<class ...A>
void in(A & ... a) {
	auto b={qp(a)...};
}
#define g(T,A...) T A;in(A);

int main() {
	g(string,s);
	int tc = 0;
	int kill = 0;
	FORD(i,0,s.length()) {
		if (s[i] == 'T') {
			tc++;
		} else {
			if (tc > 0) {
				tc--;
				kill++;
			}
		}
	}
	cout << s.length() - 2 * kill << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

//const ll INF=(ll)1e19;
const int INF=(1<<30);


int main(){
  int n,x;
  cin >> n >> x;
  int m;
  int min_m = INF;;
  REP(i,n){
    cin >> m;
    x -= m;
    min_m = min(min_m,m);
  }
  cout << n + x/min_m << endl;
}



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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
   
  int answer=0;
  
  while(true){
    bool odd=false;
    for(int i=0;i<N;i++){
      if(A.at(i)%2==1){
        odd=true;
      }
    }
    if(odd){
      break;
    }
    else{
      for(int i=0;i<N;i++){
        A.at(i)/=2;
      }
      answer++;
    }
   }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int main(){ 
  int x, n;
  cin >> x >> n;
  set<int> st;
  rep(i,n) {
    int p;
    cin >> p;
    st.insert(p);
  }
  int res = 2e9;
  for (int i = -200; i <= 200; i++) {
    if (st.count(i)) continue;
    res = min(res, abs(x - i));
  }
  int ans = 2e9;
  for (int i = -200; i <= 200; i++) {
    if (st.count(i)) continue;
    if (abs(x - i) == res) ans = min(ans ,i);
  }
  cout << ans << endl;
  return 0;
} 

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

void chmin(int& a, int b){
    a = min(a, b);
}

int N;
vector<int> child[1000];
int X[1000];

int dp[1000], sub[5001], sub2[5001];

const int INF = 1e8;

void dfs(int i){
    for(int j : child[i]) dfs(j);
    for(int j=0; j<=5000; j++) sub[j] = INF;
    sub[0] = 0;
    for(int j : child[i]){
        for(int j=0; j<=5000; j++) sub2[j] = INF;
        int s = X[j] + dp[j]; 
        for(int k=0; k<=5000; k++) for(int v : {X[j], dp[j]}) if(k+v<=5000) chmin(sub2[k+v], sub[k] + s - v);
        for(int j=0; j<=5000; j++) sub[j] = sub2[j];
    }
    dp[i] = INF;
    for(int j=0; j<=X[i]; j++) chmin(dp[i], sub[j]);
    if(dp[i] == INF){
        cout << "IMPOSSIBLE" << endl;
        exit(0);
    }
}

int main(){
    cin >> N;
    for(int i=1; i<N; i++){
        int p;
        cin >> p;
        child[p-1].push_back(i);
    }
    for(int i=0; i<N; i++) cin >> X[i];

    dfs(0);
    cout << "POSSIBLE" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[200010];
map<int, int> mp;
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        for(int i=1; i<=n; ++i){
            scanf("%d",a+i);
            if(mp.count(a[i]-i))	
	            ans+=mp[a[i]-i];
            ++mp[-a[i]-i];
        }
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 13816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

int n, a[101010], b[101010], c[101010];

int main(){
  cin >> n;
  rep(i, n){
    cin >> a[i];
  }
  rep(i, n){
    b[i] = c[i] = 0;
  }
  b[0] = a[0]; c[n - 1] = a[n - 1];
  for(int i = 1; i < n; i++){
    b[i] = __gcd(b[i - 1], a[i]);
  }
  for(int i = n - 2; i >= 0; i--){
    c[i] = __gcd(c[i + 1], a[i]);
  }
  rep(i, n) cerr << b[i] <<" ";cerr << endl;
  rep(i, n) cerr << c[i] << " "; cerr << endl;
  
  int res = 0;
  for(int i = 1; i < n - 1; i++){
    int tmp = __gcd(b[i - 1], c[i + 1]);
    res = max(tmp, res);
  }
  res = max(b[n - 2], res);
  res = max(c[1], res);
  
  cout << res << endl;
  return 0;
}


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

int main() {
	vector<vector<int>> vec(3,vector<int>(3));
	for(int i=0;i<3;++i)
	{
	    for(int j=0;j<3;++j)
	    {
	        cin>>vec[i][j];
	    }
	}
	
	int n;
	cin>>n;
	vector<int> a;
	for(int i=0;i<n;++i)
	{
	    int temp;
	    cin>>temp;
	    a.push_back(temp);
	}
	sort(a.begin(),a.end());
	int flag=0;
	for(int i=0;i<3;++i)
	{
	    for(int j=0;j<3;++j)
	    {
	        if(binary_search(a.begin(),a.end(),vec[i][j]))
	        {
	            vec[i][j]=1;
	        }
	        else
	            vec[i][j] = 0;
	    }
	}
	
	for(int i=0;i<3;++i)
	{
	    int sum=0;
	    for(int j=0;j<3;++j)
	    {
	        sum+=vec[i][j];
	    }
	    if(sum==3)
	    {
	        flag=1;
	        break;
	    }
	}
	
	for(int i=0;i<3;++i)
	{
	    int sum=0;
	    for(int j=0;j<3;++j)
	    {
	        sum+=vec[j][i];
	    }
	    if(sum==3)
	    {
	        flag=1;
	        break;
	    }
	}
	int sum=0;
	for(int i=0;i<3;++i)
	{
	    sum+=vec[i][i];
	    
	}
	if(sum==3)
	flag=1;
	
	sum=0;
	for(int i=0;i<3;++i)
	{
	    sum+=vec[i][2-i];
	    
	}
	if(sum==3)
	flag=1;
	
	if(flag==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>

long long lcm(long long a, long long b) {
    long long i = 2;
    std::map<long long, long long> m;

    // aについて、素因数分解をする。
    while(a != 1) {
        long long count = 0;
        while (a % i == 0) {
            count++;
            a /= i;
        }
        if (count != 0) {
            m[i] = count;
        }
        i++;
    }

    i = 2;
    // bについて、素因数分解をする。
    while(b != 1) {
        long long count = 0;
        while (b % i == 0) {
            count++;
            b /= i;
        }
        if (count != 0) {
            m[i] = std::max(m[i], count);
        }
        i++;
    }

    // 最小公倍数を計算する
    long long ret = 1;
    for (auto tmp : m) {
        for (long long j = 0; j < tmp.second; j++)
        {
            ret *= tmp.first;
        }
    }
    return ret;
}

int main(void) {
    long long a, b;

    std::cin >> a >> b;

    std::cout << lcm(a, b) << std::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.PrintWriter;
import java.util.Arrays;

public class Main {
	public static long l=0,l2=0;
	public static void main(String[] args) throws IOException {
		l = System.currentTimeMillis();
		new Main().exec();
		l2 = System.currentTimeMillis();
		
	}

	public void exec() throws IOException {
		InputUtil in = new InputUtil();
		PrintWriter out = new PrintWriter(System.out);
		int A = in.nextInt();
		int B= in.nextInt();
		int C = in.nextInt();
		int D = in.nextInt();
		int switchOnMax = Math.max(A, C);
		int switchOffMin = Math.min(B, D);
		if(switchOnMax < switchOffMin)
			out.println(switchOffMin - switchOnMax);
		else
			out.println(0);
		out.flush();
	}
}






class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private char[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private BufferedReader br = null;
	
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));}
	protected void initBuf(int bufsiz) {buf = new char[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			if(max>0) Arrays.fill(buf,0,max,(char)0);
			max = br.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(char b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		char c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}

Measured memory_bytes: 21204
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>

using namespace std;


int main(){
  int W,H,x,y,r;
  cin >> W >> H >> x >>y >> r;
  int x_min,y_min,x_max,y_max;
  x_min = x - r;
  x_max = x + r;
  y_min = y - r;
  y_max = y + r;

  if ((x_min >= 0) && (x_max <= W) && (y_min >= 0) && (y_max <= H)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
}
return 0;
}


Measured memory_bytes: 3096
MOD = 10**9+7
lim = 200000
inv_t = [-1 for i in range(lim+1)]
factrial = [-1 for i in range(lim+1)]
factrial_inv = [-1 for i in range(lim+1)]


def mod_inv(x, mod=MOD):
    y, u, v, _x = mod, 1, 0, x
    while y:
        t = _x//y
        _x -= t*y
        _x, y = y, _x
        u -= t*v
        u, v = v, u
    u %= mod
    if u < 0:
        u += mod
    return u


def mod_pow(a, n, mod=MOD):
    res = 1
    while n:
        if n & 1:
            res = res*a % mod
        a = a*a % mod
        n >>= 1
    return res


def COMinit(max=lim, mod=MOD):
    factrial[0] = factrial_inv[0] = 1
    factrial[1] = factrial_inv[1] = 1
    inv_t[0] = inv_t[1] = 1
    for i in range(2, max):
        factrial[i] = factrial[i-1]*i % mod
        inv_t[i] = mod-inv_t[mod % i]*(mod//i) % mod
        factrial_inv[i] = factrial_inv[i-1]*inv_t[i] % mod


def comb(a, b, mod=MOD):
    if a < b:
        return 0
    if factrial[0] == -1:
        COMinit()
    return (factrial[a]*factrial_inv[b]*factrial_inv[a-b]) % mod


n, k = [int(_) for _ in input().split()]
for i in range(k):
    print(comb(n-k+1, i+1)*comb(k-1, i) % MOD)


Measured memory_bytes: 27148
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<iomanip>
#define N 200005
#define mod 1000000007
using namespace std;
long long a[N],n,m,A,B,ans,res;
long long pm(long long x,long long n){
	long long tmp=1;
    while(n){
        if(n&1)	tmp=(tmp*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return tmp;
}
long long C(long long n,long long m){
    long long x=a[n];
    long long y=(a[m]*a[n-m])%mod;
    return (x*pm(y,mod-2))%mod;
}
int main(){
	cin>>n>>m>>A>>B;
    a[0]=1;res=0;
    for (long long i=1;i<N;i++)	a[i]=(a[i-1]*i)%mod; 
    for (long long i=B+1;i<=m;i++){
        ans=(C(i-1+n-A-1,n-A-1)*C(m-i+A-1,m-i))%mod;
        res=(res+ans)%mod;
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a == 1 && b == 2 || a==2 && b==1)
        cout<<"3"<<endl;
    else if(a == 1 && b == 3 || a == 3 && b == 1)
        cout<<"2"<<endl;
    else if(a == 2 && b == 3 || a == 3 && b == 2)
        cout<<"1"<<endl;
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>

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

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


int main() {

	string str;
	cin >> str;

	rep(i, 0, str.length()) {
		if(i%2==0)cout << str[i];
	}
	cout << endl;


	

	return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vs s(n);
  map<string,ll> a;
  rep(i,n){
    string s; cin>>s;
    a[s]++;
  }
  ll m; cin>>m;
  map<string,int> b;
  rep(i,m){
    string t; cin>>t;
    b[t]++;
  }
  ll ans=0;
  for(auto e: a){
    chmax(ans,e.second-b[e.first]);
  }
  for(auto e: b){
    chmax(ans,-e.second+a[e.first]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back
#define MAX 1e16
#define SIZE 1e8
#define mod 1000000007


using namespace std;




int main()
{
	lli N,i,t,ans = 1,minus = 1;
	
	cin>>N;
	
	for(i=1;i<=N;i++){
		cin>>t;
		if(t%2 == 0)
			minus *= 2;
		ans*=3;
	}
	ans -= minus;
	
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char** argv)
{
	while (true)
	{
		int height, width;
		std::cin >> height >> width;

		if (height == 0 && width == 0)
		{
			break;
		}

		for (int h = 0; h < height; ++h)
		{
			for (int w = 0; w < width; ++w)
			{
				std::cout << "#";
			}
			std::cout << std::endl;
		}

		std::cout << std::endl;
	}
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll H,W,h,w; cin >> H >> W >> h >> w;
	if(H%h==0 && W%w==0){
		puts("No");
		return 0;
	}
	puts("Yes");
	vvl ans(H,vl(W,-1));
	for(ll i=h-1; i<H; i+=h){
		for(ll j=w-1; j<W; j+=w){
			ans[i][j] = -1e9;
		}
	}
	for(ll i=0; i<H; i+=h){
		for(ll j=0; j<W; j+=w){
			ans[i][j] = 1e9-1;
		}
	}
	rep(i,H){
		rep(j,W) cout << ans[i][j] << " ";
		cout << endl;
	}
}

Measured memory_bytes: 4864
S = input()

#print(S)
ans = []

for str in S:
    if str == '0':
        ans.append('0')
    elif str == '1':
        ans.append('1')
    else:
        if len(ans) > 0:
            ans.pop()
            

for a in ans:
    print(a,end ="")


print()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
string b;
int a,c;
double d;
stringstream ss;
int main()
{
	cin>>a>>b;
	ss<<b,ss>>c;
	d=sqrt(a*pow(10,b.size())+c);
	if(d-(int)d==0) puts("Yes");
	else puts("No");
	return 0; 
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>a(n),b(n);
  rep(i,0,n)cin>>a[i]>>b[i];
  bitset<30>x=k;
  rrep(i,30,0){
    if(!x[i])continue;
    else{
      ll ret=0;
      rep(j,0,n){
        bitset<30>y=a[j];
        judge=true;
        rep(o,0,30){
          if(o==i&&y[o])judge=false;
          if(o>i&&y[o]&&!x[o])judge=false;
        }
        if(judge)ret+=b[j];
        //cout<<ret spa i spa j<<endl;
      }
      //cout<<i spa ret<<endl;
      chmax(res,ret);
    }
  }

  ll ret=0;
  rep(j,0,n){
    bitset<30>y=a[j];
    judge=true;
    rep(o,0,30){
      if(y[o]&&!x[o])judge=false;
    }
    if(judge)ret+=b[j];
  }
  chmax(res,ret);


  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

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

int gcd(int a, int b)
{
    if (!a) return b;
    return gcd(b % a, a);
}

int main()
{
    string B[11];
    while (1) {
        vector<string> spells;
        int h, w; cin >> h >> w;
        if (!h) break;

        loop (h, i) cin >> B[i];

        int m = h * w / gcd(h, w);
        loop (h, i) loop (w, j) {
            int x = i, y = j;
            string left(w, ' ');
            left[0] = B[i][j];
            loop (w, k) {
                left[k] = B[x][y];
                y = (y + w - 1) % w;
            }
            spells.push_back(left);
            string right(w, ' ');
            x = i, y = j;
            loop (w, k) {
                right[k] = B[x][y];
                y = (y + 1) % w;
            }
            spells.push_back(right);
            string up(h, ' ');
            x = i, y = j;
            loop (h, k) {
                up[k] = B[x][y];
                x = (x + h - 1) % h;
            }
            spells.push_back(up);
            string down(h, ' ');
            x = i, y = j;
            loop (h, k) {
                down[k] = B[x][y];
                x = (x + 1) % h;
            }
            spells.push_back(down);

            vector<string> diags(4);
            loop (4, k) diags[k] = string(m, ' ');
            loop (4, p) {
                x = i, y = j;
                loop (m, k) {
                    diags[p][k] = B[x][y];
                    x = (x + dx[p] + h) % h;
                    y = (y + dy[p] + w) % w;
                }
            }
            spells.insert(spells.end(), diags.begin(), diags.end());
        }

        sort(all(spells));
        int l = spells.size();

        int m_cnt = 1;
        string ans;
        loop (l-1, i) {
            int j = 0;
            int len = min(spells[i].size(), spells[i+1].size());
            while (j < len && spells[i][j] == spells[i+1][j]) j++;
            if (j > m_cnt) {
                m_cnt = j;
                ans = spells[i].substr(0, j);
            }
        }
        if (m_cnt == 1) cout << 0 << endl;
        else cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3392
#include<iostream>
#include<bitset>
#include<vector>
#include<queue>
using namespace std;
const int pannels=16;
const int bits=1<<pannels;
int DP[bits][32]={};
int main(){
  while(true){
  int n,c,tmp;
  cin >> n >> c; 
  if(n==0)
    break;
  queue<bitset<pannels> > qoo[2];
  vector<bitset<pannels> > light;
  vector<bitset<pannels> > push;
  for(int i=0;i<bits;i++)
    for(int j=0;j<31;j++)
      DP[i][j]=0;

  for(int i=0;i<n;i++){
    light.push_back(bitset<pannels>(0));
    for(int j=0;j<pannels;j++){
    cin >> tmp;
    light[i].set(j,tmp);
    }
    //   cout << i << endl;
  }
  for(int i=0;i<c;i++){
    push.push_back(bitset<pannels>(0));
    for(int j=0;j<pannels;j++){
    cin >> tmp;
    push[i].set(j,tmp);
    }
    //   cout << i << " push" << endl; 
  }
  bitset<pannels> lig(0),score(0),get(0);
  for(int i=0;i<c;i++){
    lig=light[0]^(light[0]&push[i]);
    get=light[0]&push[i];
    // cout << lig << endl;
    if(!DP[lig.to_ulong()][0]){
      qoo[1].push(lig);
    }
    DP[lig.to_ulong()][0]=max((int)get.count(),DP[lig.to_ulong()][0]);
  }
  //  cout << "ok" << endl;
  for(int i=1;i<n;i++){
    int push_count=0;
    while(!qoo[i%2].empty()){
      score=qoo[i%2].front();
      //  cout << score << endl;
      qoo[i%2].pop();
      for(int k=0;k<c;k++){
	lig=(score|light[i])^(push[k]&(score|light[i]));
	get=(score|light[i])&push[k];
	if(DP[lig.to_ulong()][i]==0){
	  qoo[(i+1)%2].push(lig);
	  //	  push_count++;
	}
	DP[lig.to_ulong()][i]=max((int)bitset<pannels>(get).count()+DP[score.to_ulong()][i-1],DP[lig.to_ulong()][i]);
      }
    }
    //  cout << push_count  << endl;
  }
  int ans=0;
  for(int i=0;i<bits;i++)
      ans=max(ans,DP[i][n-1]);
  cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 10272
using System;

    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            var lefter = new int[N];
            var righter = new int[N];

            if (S[0] == 'W') lefter[0]++;
            for (var i = 1; i < N; i++)
            {
                lefter[i] = lefter[i - 1];
                if (S[i] == 'W') lefter[i]++;
            }
            if (S[N-1] == 'E') righter[N - 1]++;
            for (var i = N-2; 0 <= i ; i--)
            {
                righter[i] = righter[i + 1];
                if (S[i] == 'E') righter[i]++;
            }
            var min = int.MaxValue;
            for(var i = 1;i<N-1;i++)
            {
                var count = lefter[i - 1] + righter[i + 1];
                if (count < min) min = count;
            }
            min = Math.Min(min,righter[0]);
            min = Math.Min(min,lefter[N-1]);
            Console.WriteLine(min);
        }
    }

Measured memory_bytes: 15200
from collections import Counter

n, m = map(int, input().split())
a = list(map(int, input().split()))

b = [0]
for i in a:
    b.append((b[-1]+i) % m)
 
r = 0
for v in Counter(b).values():
    r += v * (v-1) // 2
print(r)

Measured memory_bytes: 17368
package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		n      int
		result int
	)

	fmt.Scan(&n)

	cards := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(cards)))

	for i := 0; i < len(cards); i++ {
		if i%2 == 0 {
			result += cards[i]
		} else {
			result -= cards[i]
		}
	}

	fmt.Println(result)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] result = new int[100];
		int[] coin = new int[6];
		coin[0] = 500;
		coin[1] = 100;
		coin[2] = 50;
		coin[3] = 10;
		coin[4] = 5;
		coin[5] = 1;
		int index = 0;
		while( n != 0 ){
			int x = 1000-n;
			int sum = 0;
			for(int i = 0; i < 6; i++){
				sum += x/coin[i];
				x %= coin[i];
			}
			result[index] = sum;
			index++;
			n = stdIn.nextInt();
			
		}
		
		for(int i = 0; i < index; i++){
			System.out.println(result[i]);
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std ;
#define Fors(n) for(int i=1;i<=n;i++)
#define For(n) for(i=0;i<n;i++)
#define ll long long
#define vint(s) vector<int> s
#define pb(x)  push_back(x)
#define mpair(x,y) make_pair(x,y)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll x=0,y=0,s=0,n=0,i=0;

int main(){
    IOS;
    cin >> n;
    ll a[n],b[n+2];
    b[0] = 0;
    For(n){
    	cin >> a[i];
    }
    b[1] = 0;
    Fors(n){
    	
    	if (i > 2){
    		y = abs(a[i-1]-a[i-3]);
    		x= abs(a[i-1]-a[i-2]);
    		b[i] = min(b[i-2]+y,b[i-1]+x);
    	}
    	else if (i > 1){
    		x = abs(a[i-1]-a[i-2]);
    		b[i] = (b[i-1]+x);
    	}
    }
    cout << b[n] << endl;
    return 0;
}


Measured memory_bytes: 1792
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) {
    cin >> h[i];
  }

  int ans = 0;
  while (true) {
    if (*max_element(h.begin(), h.end()) == 0) break;

    int i = 0;
    while (i < n) {
      if (h[i] == 0) ++i;
      else {
        ++ans;
        while (i < n && h[i] > 0) {
          --h[i];
          ++i;
        }
      }
    }
  }

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

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<queue>
#include<functional>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<int, ll> P;

int n, m, s, t;
vector<vector<P>> edge_en;
vector<vector<P>> edge_snuke;

vector<ll> paid_cost_en;
vector<ll> paid_cost_snuke;

void djkstra(vector<ll> &dis, vector<vector<P>> &edge, int start) {
	priority_queue<P, vector<P>, greater<P>> pq;
	pq.push(P(0, start));
	dis[start] = 0;
	while (pq.size()) {
		P now = pq.top(); pq.pop();
		if (dis[now.second] < now.first)continue;
		for (int i = 0; i < edge[now.second].size(); i++) {
			P next = edge[now.second][i];
			if (dis[next.first] > dis[now.second] + next.second) {
				dis[next.first] = dis[now.second] + next.second;
				pq.push(P(dis[next.first], next.first));
			}
		}
	}
}

int main() {

	cin >> n >> m >> s >> t;
	s--, t--;
	edge_en.resize(n);
	edge_snuke.resize(n);
	paid_cost_en.resize(n);
	paid_cost_snuke.resize(n);

	for (int i = 0; i < m; i++) {
		int a, b;
		ll c, d;
		cin >> a >> b >> c >> d;
		a--, b--;
		edge_en[a].push_back(P(b, c));
		edge_en[b].push_back(P(a, c));
		edge_snuke[a].push_back(P(b, d));
		edge_snuke[b].push_back(P(a, d));

	}

	vector<ll> anslist;
	ll ans = 0;

	for (int j = 0; j < n; j++)paid_cost_en[j] = 1e17, paid_cost_snuke[j] = 1e17;
	djkstra(paid_cost_en, edge_en, s);
	djkstra(paid_cost_snuke, edge_snuke, t);
	for (int i = n - 1; i >= 0; i--) {
		ans = max(ans, (ll)1e15 - paid_cost_en[i] - paid_cost_snuke[i]);
		anslist.push_back(ans);
	}
	reverse(anslist.begin(), anslist.end());
	for (int i = 0; i < n; i++)cout << anslist[i] << endl;
	return 0;
}

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

int main(int argc, char const *argv[])
{
    int K, S;
    cin >> K >> S;
    int c = 0, sum;
    for(int i = 0; i <= K; i ++){
        for(int j = 0; j <= K; j ++){
            sum = S - i - j;
            if (0 <= sum && sum <= K) c++;
        }
    }
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
#define INFTY 1000000000

struct Card{
  
  char suit;
  int value;
  
};

struct Card L[N], R[N];

void merge(struct Card *, int, int, int);
void mergeSort(struct Card *, int , int);
int partition(struct Card *, int, int);
void quickSort(struct Card *, int, int);



int main(){
  
  int n;
  int i;
  int v;
  struct Card A[N], B[N];
  char S[10];
  int stable;

  stable = 1;
  
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    
    scanf("%s %d", S, &v);
    
    A[i].suit = S[0];
    B[i].suit = S[0];
    A[i].value = v;
    B[i].value = v;
    
  }

  mergeSort(A, 0, n);
  quickSort(B, 0, n-1);

  for ( i = 0; i < n; i++ ){
    if ( A[i].suit != B[i].suit ) stable = 0;
  }

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ ) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }

  return 0;
}

void merge(struct Card A[], int left, int mid, int right){
  
  int i, j, k;
  int n1;
  int n2;
  
  n1 = mid - left;
  n2 = right - mid;

  for ( i = 0; i < n1; i++ ) {
    L[i] = A[left + i];
  }
  for ( i = 0; i < n2; i++ ) {
    R[i] = A[mid + i];
  }

  
  L[n1].value = INFTY;
  R[n2].value = INFTY;

  i = 0;
  j = 0;
  
  for ( k = left; k < right; k++ ){
    
    if ( L[i].value <= R[j].value ){
      A[k] = L[i];
      i++;
    }
    else {
      A[k] = R[j];
      j++;
    }
  }
}
 
void mergeSort(struct Card A[], int left, int right ){
  
  int mid;
  
  if ( left + 1 < right ){
    
    mid = (left + right)/2;
    
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(struct Card A[], int p, int r){
  
  int i, j;
  struct Card t, x;

  x = A[r];
  i = p - 1;
  
  for ( j = p; j < r; j++ ){
    
    if ( A[j].value <= x.value ){
      
      i++;
      
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
    
  }
  
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  
  return i+1;
}

void quickSort(struct Card A[], int p, int r){

  int q;
  
  if ( p < r ){
    
    q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
    
  }
  
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;

const int MOD = 1e9 + 7;

ll solve(const vector<ll>& A, const vector<ll>& B) {
  int N = A.size();
  int M = B.size();

  REP(i, N - 1) if(A[i + 1] == A[i]) return 0;
  REP(i, M - 1) if(B[i + 1] == B[i]) return 0;

  ll ret = 1;
  for(int i = N * M; i > 0; --i) {
    auto itrA = lower_bound(ALL(A), i);
    auto itrB = lower_bound(ALL(B), i);
    if((*itrA == i) && (*itrB == i)) {
      continue;
    }else if(*itrA == i) {
      ret = ret * (B.end() - itrB) % MOD;
    }else if(*itrB == i) {
      ret = ret * (A.end() - itrA) % MOD;
    }else{
      ll tmp = (A.end() - itrA) * (B.end() - itrB) - (N * M - i);
      if(tmp <= 0) return 0;
      ret = ret * tmp % MOD;
    }
  }
  return ret;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<ll> A(N), B(M);
  REP(i,N) cin >> A[i];
  REP(i,M) cin >> B[i];
  sort(ALL(A));
  sort(ALL(B));

  cout << solve(A, B) << endl;
  return 0;
}



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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a+b==c || b+c==a || c+a==b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int n,A[20];
int check(int t,int m){
    if(m==0) return 1;
    else if(t==n) return 0;
    int res = check(t+1,m) || check(t+1,m-A[t]);
    return res;
}

int main(){
    int m,p;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    
    cin >> p;
    for(int i=0; i<p; i++){
        cin >> m;
        if(check(0,m)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

Measured memory_bytes: 3068
# frozen_string_literal: true

class Minesweeper

  def initialize(h, w, data)
    @height = h
    @width = w
    @padded = pad(data)
  end

  def call
    (1..height).map {|h|
      (1..width).map {|w|
        padded[h][w] == 1 ? -1 :
        padded[h - 1][w - 1] +
          padded[h - 1][w] +
          padded[h - 1][w + 1] +
          padded[h][w - 1] +
          padded[h][w + 1] +
          padded[h + 1][w - 1] +
          padded[h + 1][w] +
          padded[h + 1][w + 1]
      }
    }
  end

  private

  attr_reader :height, :width, :padded

  def pad(data)
    ret = data.map {|row|
      row.unshift(0)
      row.push(0)
    }
    ret.unshift(Array.new(ret[0].size, 0))
    ret.push(Array.new(ret[0].size, 0))
  end

end

h, w = gets.split.map(&:to_i)
data = h.times.map { gets.chomp.split("").map {|s| s == "." ? 0 : 1 } }
matrix = Minesweeper.new(h, w, data)
matrix.call.each {|row|
  puts row.map {|value| value >= 0 ? value : "#" }.join
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
//最大公約数
long long GCD(long long a, long long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(GCD(b, a%b));
   }
}

//最小公倍数
long long LCM(long long a, long long b)
{
   return a/(GCD(a,b))*b;
}
int main() {
  long long N;
  cin >> N;
  long long ans;
  cin >> ans;
  for(long long i=0; i<N-1; i++){
    long long a;
    cin >> a;
    ans = LCM(ans,a);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3576
import sys
sys.setrecursionlimit(10**5-1)

n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if nexts is None:
    return
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))

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

using namespace std;

long long evaf(string s){
	long long ans = 0;
	long long cur = 0;
	for (int i = 0; i < (int)s.size(); i++){
		if (s[i] == '+'){
			ans += cur;
			cur = 0;
		}
		else {
			cur = cur * 10 + (s[i] - '0');
		}
	}
	ans += cur;
	return ans;
}

int main(){
	char s[11];
	scanf("%s", s);
	int n = strlen(s);
	long long ans = 0LL;
	for (int i = 0; i < (1 << (n - 1)); i++){
		string cur = "";
		for (int j = 0; j < n - 1; j++){
			cur += s[j];
			if (i & (1 << j)){
				cur += '+';
			}
		}
		cur += s[n - 1];
		ans += evaf(cur);
		//cout << cur << endl;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from bisect import bisect_left
S = input()
sl = len(S)
T = input()
t = set(T)
dic = defaultdict(list)
for c in t:
  for i, m in enumerate(S):
    if m==c:
      dic[c] += [i]
  if dic[c]==[]:
    print(-1)
    import sys
    sys.exit()
p = -1
ans = 0
pc = ''
for c in T:
  if pc==c:
    p += 1
    ans += 1
  if p>dic[c][-1]:
    ans += sl-1-p
    p = -1
  ind = bisect_left(dic[c],p)
  ans += dic[c][ind]-p
  p = dic[c][ind]
  pc = c
print(ans)

Measured memory_bytes: 48648
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);

	ll n;
	cin >> n;
	if ((n&1) == 1) {
		cout << 0 << endl;
		return 0;
	}
	n /= 2;
	ll res = 0;
	while (n) {
		res += n / 5;
		n /= 5;
	}
	cout << res << endl;
}

Measured memory_bytes: 256