akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
static const double pi=3.14159265358979;
int main(){
double A,B,H,M;
  cin>>A>>B>>H>>M;
  double ans=pow(A,2)+pow(B,2)-2*A*B*cos(pi*(H/6-M/30+M/360));
  ans=pow(ans,0.5);
  cout<<fixed<<setprecision(11)<<ans<<endl;
   return 0;
}


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

ll gcd(ll a, ll b) {
    ll ans = 0;
    int temp;

    while(true) {

        if(a % b == 0) {
            ans = b;
            break;
        }

        temp = a % b;
        a = b;
        b = temp;
    }

    return ans;
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    // c,dの最大公約数l
    ll l = (c * d) / gcd(c, d);

    // B以下のcの倍数の個数
    ll b_c = b / c;
    // B以下のdの倍数の個数
    ll b_d = b / d;
    // B以下のlの倍数の個数
    ll b_l = b / l;

    // A以下のcの倍数の個数
    ll a_c = a / c;
    // A以下のdの倍数の個数
    ll a_d = a / d;
    // A以下のlの倍数の個数
    ll a_l = a / l;
    // 計算
    ll ans = (b - b_c - b_d + b_l) - (a - a_c - a_d + a_l);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int64_t K;
  cin >> K;

  cout << (K % 2 == 0 ? 1 : -1) * (A - B) << endl;
  return 0;
}

Measured memory_bytes: 3600
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;

//main
int main(){
    ll N,K; cin >> N >> K;
    vector<int> A(N);
    vector<int> B;
    const long long c = 1000000007;
    rep(i,N){
        cin >> A[i];
        B.pb(A[i]);
    }
    rep(i,N) B.pb(A[i]);
    long long c1 = 0;
    long long c2 = 0;
    rep(i,N-1){
        for(int j=i+1; j<N; j++){
            if(A[j]<A[i]){
                c1 += 1;
            }
        }
    }
    rep(i,N){
        for(int j=N; j<2*N; j++){
            if(B[j]<B[i]){
                c2 += 1;
            }
        }
    }
    cout << (c1*K%c+(K-1)*K/2%c*c2%c)%c << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll           long long
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define scn(a)       scanf("%lld",&a)
#define nl           printf("\n")
#define scns(a,b)    scanf("%lld %lld",&a,&b)
#define print(a)     printf("%lld",a)
#define tc           ll t; scn(t); while(t--)
#define vec          vector<ll>
#define pb           push_back
#define pairs        pair<ll,ll>
#define fi           first
#define se           second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.rbegin(),v.rend())
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         5000005
#define inf          LLONG_MAX
#define zer          LLONG_MIN
#define dbug(a)      cout<<"dbug : "<<a<<endl
#define debug(a,b)    cout<<a<<" "<<b<<endl
#define read(v)      vec v(n,0); rep(i,0,n) {cin>>v[i];}
#define write(a,n)     rep(i,0,n) {cout<<a[i]<<" ";}
#define All          rep(i,0,n)

int main()
{
	int n;
	cin>>n;
	unordered_map<string , int> mp;
	rep(i,0,n)
	{
		string s;
		cin>>s;
		mp[s]++;
		
	}
	
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;


}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

vector<pair<ll,ll> > prime_factorize(ll n){
  vector<pair<ll,ll> > res;
  if(n==1)return res;
  for(ll p=2; p*p<=n; p++){
    if(n%p!=0)continue;
    int num=0;
    while(n%p==0){
      num++;
      n/=p;
    }
    res.push_back(make_pair(p,num));//pでnum回割り切れる
  }
  if(n!=1)res.push_back(make_pair(n,1));
  return res;
}

int main(){
  ll N,P;
  cin >> N >> P;
  ll ans=1;
  if(P==1){
    cout << 1 << endl;
    return 0;
  }
  auto v = prime_factorize(P);
  //cout << v[0].first << " " << v[0].second << endl;
  rep(i,v.size()){
    ans *= pow(v[i].first,v[i].second/N);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int monets;
    cin >> monets;
    size_t happy = 0;
    while (monets - 500 >= 0) {
        monets -= 500;
        happy += 1000;
    }
    
    while (monets - 5 >= 0) {
        monets -= 5;
        happy += 5;
    }
    cout << happy;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string a[200100];
int main(){
	int n;
	while(cin >> n){
		map<string, int> mp;
		string s;
		for(int i = 1; i <= n; i++){
			cin >> s;
			if(mp.find(s) != mp.end()) mp[s]++;
			else mp[s] = 1;
		}
		int x = -1, f = 0;
		
		map<string, int> :: iterator it = mp.begin();
		for(; it != mp.end(); it++){
			if(it -> second > x){
				f = 0;
				a[f++] = it -> first;
				x = it -> second;
			}
			else if(it -> second == x){
				a[f++] = it -> first;
			}
		}
//		printf("ans:\n");
		for(int i = 0; i < f; i++)
			cout << a[i] << endl;
	}
	return 0;
}

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  
    {if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;  }  return res;  
}
bool sortinrev(const pair<vector<int>,int>&a,const pair<vector<int>,int>&b){if(a.fi==b.fi)return b.se>a.se;return a.fi>b.fi;}
void run(vector<int>v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void solve()
{
    int n,W;
    cin>>n>>W;
    ll wt[n],val[n];
    for(int i=0;i<n;i++)
        cin>>wt[i]>>val[i];
    ll dp[n+1][W+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=W;j++)
        {
            if(i==0 || j==0)
                dp[i][j] = 0;
            else if(wt[i-1]<=j)
                dp[i][j] = max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][W]<<endl;
    
    

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

Measured memory_bytes: 79104
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}
#define printans(ans) {printf("%d\n",(ans));}
#define repeat(N) for(int repeat_dummy_int=0; repeat_dummy_int<N; repeat_dummy_int++)
typedef int* intarray;
typedef char* string;

int main(){
    int N, T, c, t, min = 10000;
    scanf("%d%d", &N, &T);
    repeat(N){
        scanf("%d%d", &c, &t);
        min = (t<=T && c<min) ? c : min;
    }
    if(min==10000) printf("TLE\n");
    else printans(min);
    return 0;
}

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

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

int h, w, n;
char f[31][31];

bool check(int y, int x, int flag) {
  char tmp[31][31];
  memcpy(tmp, f, sizeof(f));
  swap(tmp[y][x], tmp[y + !flag][x + flag]);
  
  while (true) {
    for (int j = 0; j < w; j++) {
      for (int i = h - 1; i >= 0; i--) {
        if (tmp[i][j] == '.') continue;
        int l = i, r = i;
        while (r + 1 < h && tmp[r + 1][j] == '.') r++;
        tmp[r][j] = tmp[l][j];
        if (l != r) tmp[l][j] = '.';
      }
    }

    bool update = false, erase[31][31] = {};
    for (int i = 0; i < h; i++) {
      for (int j = 0; j + n - 1 < w; j++) {
        if (tmp[i][j] == '.') continue;
        int l = j, r = j;
        while (r < w && tmp[i][r] == tmp[i][l]) r++;
        if (r - l >= n) {
          for (int k = l; k < r; k++) erase[i][k] = true;
          update = true;
        }
      }
    }
    for (int j = 0; j < w; j++) {
      for (int i = 0; i + n - 1 < h; i++) {
        if (tmp[i][j] == '.') continue;
        int l = i, r = i;
        while (r < h && tmp[r][j] == tmp[l][j]) r++;
        if (r - l >= n) {
          for (int k = l; k < r; k++) erase[k][j] = true;
          update = true;
        }
      }
    }
    if (!update) break;

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (erase[i][j]) tmp[i][j] = '.';
      }
    }
  }

  bool res = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) res &= tmp[i][j] == '.';
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin >> h >> w >> n;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cin >> f[i][j];
  }

  bool ans = false;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j + 1 < w) ans |= check(i, j, 1);
    }
  }
  cout << (ans ? "YES" : "NO") << endl;

  return 0;
}


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

class Progaram
{
    static void Main(string[] args)
    {
        var line = Console.ReadLine().Split(' ')
            .Select(x => int.Parse(x)).ToList();
        var n = line[0];
        var m = line[1];
        var sl = new List<int>();
        var cl = new List<int>();
        for (var i = 0; m > i; i++)
        {
            var l = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToList();
            sl.Add(l[0]);
            cl.Add(l[1]);
        }

        var al = -1;
        for (var i = 0; 1000 > i; i++)
        {
            var io = i.ToString().ToCharArray();
            if (io.Length == n)
            {
                var or = true;
                for (var j = 0; m > j; j++)
                {
                    if (int.Parse(io[sl[j] - 1].ToString()) != cl[j])
                    {
                        or = false;
                        break;
                    }
                }
                if (or)
                {
                    al = i;
                    break;
                }
            }
        }
        Console.WriteLine(al);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define ll long long
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define INF 1000000000
#define M 1000000007ll
int n,x,y,z,S;
ll f[300005],inv[300005];
ll expo(ll a,ll b) {
	if (!b) return 1ll;
	ll x=expo(a,b/2ll);
	if (b%2ll) return (((x*x)%M)*a)%M;
	return (x*x)%M;
}
ll choose(int n,int k) {
	return (((f[n]*inv[n-k])%M)*inv[k])%M;
}
ll mem[45][70005];
vector<int> v;
void to(int b) {
	v.clear();
	int cur=0;
	bool start=0;
	for (int j=S-1;j>=0;j--) {
		if (b&(1<<j)) {
			if (start) v.pb(cur);
			else start=1;
			cur=1;
		} else cur++;
	}
	v.pb(cur);
}
bool has() {
	bool cz=0,cy=0,cx=0;
	int k=sz(v)-1;
	int s=0;
	while(k>=0) {
		s+=v[k];
		if (s==z) {
			cz=1;
			k--;
			break;
		}
		k--;
	}
	if (cz) {
		s=0;
		while(k>=0) {
			s+=v[k];
			if (s==y) {
				cy=1;
				k--;
				break;
			}
			k--;
		}
		if (cy) {
			s=0;
			while(k>=0) {
				s+=v[k];
				if (s==x) {
					cx=1;
					k--;
					break;
				}
				k--;
			}
		}
	}
	return cx;
}
int main() {
	scanf("%d%d%d%d",&n,&x,&y,&z);
	S=x+y+z-1;
	for (int j=1;j<=10;j++) {
		mem[1][(1<<(j-1))%(1<<S)]++;
	}
	for (int i=1;i<n;i++) {
		for (int b=0;b<(1<<S);b++) {
			if (mem[i][b]>0ll) {
				to(b);
				for (int j=1;j<=10;j++) {
					v.pb(j);
					if (!has()) {
						int nb=(b<<j)|(1<<(j-1));
						nb%=(1<<S);
						mem[i+1][nb]+=mem[i][b];
						mem[i+1][nb]%=M;
					}
					v.pop_back();
				}
			}
		}
	}
	ll ans=0ll;
	for (int b=0;b<(1<<S);b++) ans+=mem[n][b],ans%=M;
	ans=M-ans+expo(10ll,n);
	printf("%lld\n", ans%M);
}


Measured memory_bytes: 19328
n=int(input())
s1=input()
s2=input()
mod=1000000007
t=0
flg=True
ans=1
while t<n:
    if t==0:
        if s1[t]==s2[t]:
            t+=1
            ans*=3
        else:
            t+=2
            ans*=6
            flg=False
    elif flg and s1[t]==s2[t]:
        ans*=2
        ans%=mod
        t+=1
    elif flg and s1[t]!=s2[t]:
        t+=2
        ans*=2
        ans%=mod
        flg=False
    elif flg==False and s1[t]==s2[t]:
        flg=True
        t+=1
    elif flg==False and s1[t]!=s2[t]:
        t+=2
        ans*=3
        ans%=mod
print(ans%mod)

Measured memory_bytes: 61912
#include <iostream>
#include<string.h>
using namespace std;


int main() {

	int A;
	int B;
	string S;
	string T;
	string U;
	
	cin >> S >> T >> A >> B >> U;

	if (S == U) {
		A = A - 1;
	}
	else
	{
		B = B - 1;
	}

	cout << A <<" "<< B << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=200001;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int a[12]={1,3,1,2,1,2,1,1,2,1,2,1};
	int x,y;
	cin>>x>>y;
	x--,y--;
	if(a[x]==a[y])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
// Ballazt
//0a..brute force
//0b..greedy
//1..memorizatton of some sort	remember something cleverly
//2..sort
//3..binary search	keep check a particular solution
//4..dp				repeating strucutre,limited choices
//5..dfs/bfs		matrix with obstacles
//6..correlate to graph in some way		each state is a point
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"


int main()

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

	
	int h1,s1,h2,s2;
	cin>>h1>>s1>>h2>>s2;

	while(h1>0&&h2>0)
	{
		if(h2-s1>0) h2-=s1;
		else if (h2-s1<=0)
		{
			cout<<"Yes";
			return 0;
		}

		if(h1-s2>0) h1-=s2;
		else if (h1-s2<=0)
		{
			cout<<"No";
			return 0;
		}
	}

	
	return 0;

	
}

Measured memory_bytes: 3656
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, s, as = 0, nas;
  cin >> n >> s;
  nas = n;
  for (int i = 0; i < nas; i++) {
    if (2 * n + 4 * as == s) {
      cout << "Yes" << endl;
      return 0;
    }
    // cout << i << endl;
    else if (4 * n + 2 * as > s) {
      // cout << 4 * n + 2 * as << endl;
      n--;
      as++;
    } else if (4 * n + 2 * as == s) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3648
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,k,a[100005],ans;
vector<int> v[100005];
int dfs(int x){
    int ret=0;
    for(int i=0;i<v[x].size();++i)ret=max(ret,dfs(v[x][i]));
    if(x==1) return 0;
    ++ret;
    if(ret==k&&a[x]!=1){
        ++ans;
        return 0;
    }
    return ret;
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i)scanf("%d",a+i);
    if(a[1]!=1)ans=1;
    for(int i=2;i<=n;++i)v[a[i]].pb(i);
    dfs(1);
    printf("%d\n",ans);
    //system("pause");
    return 0;
}


Measured memory_bytes: 12288
#include<iostream>
#include<vector>
using namespace std;
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define chmax(a,b) a=max(a,b)

int n,m,ans;
vi vis,topo;
vi dp;
vvi e;

void dfs(int x)
{
	if(vis[x]) return;
	vis[x]=1;
	for(int i=0;i<e[x].size();i++)
		dfs(e[x][i]);
	topo.pb(x);
}

int main()
{
	
	cin>>n>>m;
	e.resize(n);
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		e[x].pb(y);
	}
	
	vis.resize(n);
	for(int i=0;i<n;i++)
		dfs(i);
	dp.resize(n);
	for(int i=0;i<topo.size();i++)
	for(int j=0;j<e[topo[i]].size();j++)
		chmax(dp[topo[i]],dp[e[topo[i]][j]]+1);
	for(int i=0;i<n;i++)
		chmax(ans,dp[i]);
	cout<<ans<<'\n';
	
	return 0;
}

Measured memory_bytes: 8440
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n; cin >> n;
  VI nums(n);
  for (int i = 0; i < n; ++i)
    cin >> nums[i];
  sort(nums.begin(), nums.end());
  if (unique(nums.begin(), nums.end()) == nums.end()) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}



Measured memory_bytes: 1024
n,k = map(int,input().split())
dic = {}
for i in range(n):
  a,b = map(int,input().split())
  if a in dic:
    dic[a] += b
  else:
    dic[a] = b
dic2 = sorted(dic.items()) 
count = 0
for i in range(len(dic2)):
  count += dic2[i][1]
  if count >= k:
    print(dic2[i][0])
    break
  
  


Measured memory_bytes: 14560
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

int dp[200001];
vector<int> works_on[200001];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k;
    string s;
    cin >> n >> m >> k >> s;
    int mx = 0;
    for (int i = n - 1; ~i; i--) {
        if (s[i] == 'o') {
            dp[i] = mx + 1;
            works_on[dp[i]].push_back(i + 1);
        }
        if (i + k < n) mx = max(mx, dp[i + k]);
    }

    if (dp[0] == m) {
        int curr = 0;
        for (int i = m; i; i--) {
            while (works_on[i].back() <= curr) works_on[i].pop_back();
            curr = works_on[i].back() + k;

            if (works_on[i].size() == 1) cout << works_on[i][0] << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 13460
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = int;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  int n; cin >>n;
  map<int, int> mp;
  for(int i = 0; i < n; ++i){
    int a;cin >>a;
    ++mp[a-1];
    ++mp[a];
    ++mp[a+1];
  }
  int ans=0;
  for(auto it : mp){
    ans=max(ans,it.second);
  }
  cout << ans << endl;
}



Measured memory_bytes: 4736
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

int main() {
	ll N;
	cin >> N;

	vi D(N);
	ll ans = 1;

	rep(i, N) {
		cin >> D[i];
	}

	if (D[0] != 0)
	{
		cout << 0 << endl;
		return 0;
	}

	sort(all(D));

	ll ln = 1;
	ll cn = 0;
	ll last = 1;

	repa(i, 1, N) {
		if (D[i] != last) {

			if (D[i] - last != 1) {
				ans = 0;
				break;
			}

			last = D[i];
			ln = cn;
			cn = 0;
		}
		cn++;
		ans *= ln;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main(void){
    int N,T;
    int c_min=1234567,c,t;
    int i;
    cin>>N>>T;

    for(i=0;i<N;i++){
        cin>>c>>t;
        if(t<=T){
            if(c<c_min){
                c_min=c;
            }
        }
    }
    if(c_min == 1234567){
        cout<<"TLE"<<endl;
    }else{
        cout<<c_min<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <list>

using lli = long long int;

constexpr int BitSize = 63;
std::vector<lli> A;

int main(void){
    int n, k; scanf("%d%d", &n, &k);
    A.resize(n+1); A[0] = 0;
    for(int x = 1; x <= n; ++x) scanf("%lld", &A[x]);
    for(int x = 1; x <= n; ++x) A[x] += A[x-1];
    std::list<lli> lst;
    for(int x = 0; x <= n; ++x){
        for(int y = x + 1; y <= n; ++y) lst.push_back(A[y] - A[x]);
    }
    lli res = 0;
    for(int pos = BitSize; pos >= 0; pos--){
        if(lst.size() < k) break;
        int cnt = 0;
        for(lli val : lst) if((val >> pos) & 1) cnt++;
        if(cnt < k) continue;
        res += (1LL << pos);
        for(auto itr = lst.begin(); itr != lst.end();){
            if(!( ((*itr) >> pos) & 1)) itr = lst.erase(itr);
            else itr++;
        }
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main()
{
ll a,b,c,d,e,f,g,h,t,tt,ans;
cin>>a>>b>>c>>d;
e=a*c;
f=a*d;
g=b*c;
h=b*d;
t=max(e,f);
tt=max(g,h);
ans=max(t,tt);
cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <vector>
#include <algorithm>
#include <limits.h>
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <unordered_map>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

      int n; int W; cin>>n;
      cin>>W;

      int w[n],v[n];
      for(int i=0;i<n;i++){cin>>w[i]>>v[i];}

      int maxV=1e5+1;
       long long  f[n+1][maxV+1];
      for(int i=0;i<=maxV;i++){f[0][i]=INT_MAX;}
      for(int i=0;i<=n;i++){f[i][0]=0;}
        // f[0][v[0]]=w[0];
      for(int i=1;i<=n;i++)
      {
          for(int j=1;j<=maxV;j++)
          {
              f[i][j]=f[i-1][j];
              if(j-v[i-1]>=0){f[i][j]=min(f[i][j],f[i-1][j-v[i-1]]+w[i-1]);}
              //cout<<f[i][j]<<" ";
          }
         // cout<<"\n";
      }
    long long  ans=0;
    for(int i=maxV;i>=0;i--)
    {
        for(int j=n;j>=0;j--)
        {
            if(f[j][i]<=W)
            {
                ans=i;
                break;
            }
        }
        if(ans>0)
            break;
    }
      cout<<ans<<"\n";



    return 0;
}

Measured memory_bytes: 79232
import sys
a, b = map (int, sys.stdin.readline().split())
s = sys.stdin.readline().strip()
ok = 0
if s[a] == '-':
  t = s.split('-')
  if len (t) == 2:
    if len (t[0]) == a and len (t[1]) == b:
      ok = 1

print (["No", "Yes"][ok])

Measured memory_bytes: 3060
a = int(input())
v = []
v.append(a)
t = 1
i = -1
while t == 1:
    i += 1
    if v[i] % 2 == 1:
        b = (v[i] * 3) + 1
        if b not in v: 
            v.append(b)
        else:
            v.append(b)
            break;
            ans = i
    else:
        b = (v[i]//2)
        if b not in v:
            v.append(b)
        else:
            v.append(b)
            break;
            ans = i

print(i+2)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main(void) {
    int n;
    std::scanf("%d", &n);
    long long x = 1;
    while (x * x <= n) {
        x++;
    }
    x--;
    std::printf("%lld\n", x * x);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
using namespace std;
 
#define INF 1<<21
#define MAX 100005
#define MOD 10e9+7
 
int main(){
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=100000;i++){
        if(i*i>n){
            cout<<ans<<endl;
            return 0;
        }
        ans=i*i;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
int ma=0;
int ss[200001];
int ans[200001];
int it[200001];
vector<int> adj[200001];
void dfs(int no,int par=-1){
	pair<int,pair<int,int>> rev;
	if(ma==0){
		ss[0]=it[no];
		ma+=1;
		rev={-1,{-1,-1}};
	}
	else if(it[no]>ss[ma-1]){
		ma+=1;
		ss[ma-1]=it[no];
		rev={-1,{-1,-1}};
	}
	else{
		auto ind=lower_bound(ss,ss+ma,it[no])-ss;
		rev={ind,{ss[ind],it[no]}};
		ss[ind]=it[no];
	}
	ans[no]=ma;
	for(auto j:adj[no]){
		if(j==par){
			continue;
		}
		dfs(j,no);
	}
	if(rev.a!=-1){
		ss[rev.a]=rev.b.a;
	}
	else{
		ma-=1;
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>it[i];
	}
	int aa,bb;
	for(int i=0;i<n-1;i++){
		cin>>aa>>bb;
		adj[aa-1].pb(bb-1);
		adj[bb-1].pb(aa-1);
	}
	dfs(0,-1);
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}

	return 0;
}

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

int main() {
    string s, t;
    bool flag = false;
    cin >> s >> t;
    rep(i, s.length()) {
        string temp = s.substr(i, s.length()) + s.substr(0, i);
        if(temp == t) flag = true;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
vector<int> a[N];
int f[N];

int find(int x) {
  if (f[x] != f[f[x]]) f[x] = find(f[x]);
  return f[x];
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int len;
    scanf("%d", &len);
    while (len--) {
      int x;
      scanf("%d", &x);
      --x;
      a[x].push_back(i);
    }
    f[i] = i;
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 1; j < a[i].size(); ++j) {
      int x = a[i][j - 1], y = a[i][j];
      int rx = find(x), ry = find(y);
      if (rx != ry) {
        f[ry] = rx;
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    if (find(i) == i) ++ret;
  }
  puts(ret == 1 ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define U [1<<17]={}
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
    d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}
L M(L i){return i?B[i]+M(i-(i&-i)):0;}
L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}
L W(){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}
main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(c=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;S(a=H[a],O[a]=c++))X[a]=p;
       for(cin>>a;cin>>s>>a>>b;*s&2?W():A[a]+=b,S(H[a],O[a]),a?S(a,O[a]-1):0);}

Measured memory_bytes: 33472
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

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

  bool ok = true;
  rep(i,n) ok &= v[i]%2 == 0;

  cout << (ok ? "second" : "first") << endl;


  return 0;
}


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

int main(){
    int N,A,B;
    cin >> N >> A >> B;

    string Ans = "NG";

    for(int i = 0; i<=B-A ; i++){
        if((A + i) % N == 0) {
            Ans = "OK";
    }
    }
cout << Ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define sort_v(a) sort(a.begin(), a.end())

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

vi x, y;

bool inx(int n, vi z)
{
    rep(i, 0, z.size())
    {
        if (z[i] == n)
            return true;
    }
    return false;
}

int main()
{
    int h, w;
    cin >> h >> w;
    string a[h];
    rep(i, 0, h)
    {
        cin >> a[i];
    }

    rep(i, 0, h)
    {
        bool white = true;
        rep(j, 0, w)
        {
            if (a[i][j] == '#')
            {
                white = false;
                break;
            }
        }
        if (white)
            y.push_back(i);
    }
    rep(i, 0, w)
    {
        bool white = true;
        rep(j, 0, h)
        {
            if (a[j][i] == '#')
            {
                white = false;
                break;
            }
        }
        if (white)
            x.push_back(i);
    }
    rep(i, 0, h)
    {
        bool f = false;
        rep(j, 0, w)
        {
            if (!inx(j, x) && !inx(i, y))
                cout << a[i][j];
            if (inx(i, y))
                f = true;
        }
        if (!f)
            cout << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
typedef uint64_t ull;
typedef  int64_t sll;

ull h, w, k;
char s[3010][3010], t[3010][3010];

void drop () {
	sll i, j;
	for (j = 0; j < w; j++) {
		sll bottom = h - 1;
		for (i = h - 1; i >= 0; i--) {
			if (t[i][j]) {
				t[bottom--][j] = t[i][j];
			}
		}
		while (bottom >= 0) {
			t[bottom--][j] = '\0';
		}
	}
}

ull rensa () {
	sll i, j;
	ull r = 0;
	for (i = 0; i < h; i++) {
		j = 0;
		while (j < w) {
			if (!t[i][j]) {
				j++;
				continue;
			}

			sll ki = j;
			while (j < w && t[i][j] == t[i][ki]) j++;

			if (j - ki >= k) {
				r += (j - ki) * (t[i][ki] - '0');
				while (ki < j) {
					t[i][ki] = '\0';
					ki++;
				}
			}
		}
	}

	return r;
}

ull f (ull a, ull b) {
	sll i, j;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			t[i][j] = s[i][j];
		}
	}
	t[a][b] = '\0';

	ull r = 0;
	for (i = 0; ; i++) {
		drop();
		ull x = rensa() << i;
		if (!x) return r;

		r += x;
	}
}

ull solve () {
	ull result = 0;
	if (k > 3) {
		puts("0");
		return 1;
	}

	for (sll i = 0; i < h; i++) {
		for (sll j = 0; j < w; j++) {
			ull item = f(i, j);
			if (item > result) result = item;
		}
	}

	printf("%lld\n", result);
	return 0;
}

int32_t main (void) {
	int32_t i, j;
	int32_t x, y;

	scanf("%llu%llu", &h, &w);
	scanf("%llu", &k);
	for (i = 0; i < h; i++) {
		scanf("%s", &s[i]);
	}

	solve();

	return 0;
}


Measured memory_bytes: 2304
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
// 1. dp?????????
ll dp[100001];
// 2. n?????????
ll N,T,Q;
ll A[100001];
int D[100001];

// 7. calc?????????
ll calc(int k){
	// 8. dp???????????°??????
	if(dp[k]!=A[k])return dp[k];
	// 9. dp????¨????

	if(D[k]==1){
		if(D[k+1]==1){
			dp[k]=min(A[k]+T,calc(k+1));
		}else{
			dp[k]=min((A[k]+A[k+1])/2,A[k]+T);
		}
	}
	if(D[k]==2){
		if(D[k-1]==2){
			dp[k]=max(A[k]-T,calc(k-1));
		}else{
			dp[k]=max((A[k]+A[k-1])/2,A[k]-T);
		}
	}

	return dp[k];
}
int main() {
	cin>>N>>T>>Q;

	//3.?????????

	//4.??\???
	for(int i=1;i<N+1;i++){
		cin>>A[i]>>D[i];
		dp[i]=A[i];
	}

	//5.???????????¨???

	if(D[1]==2){
		dp[1]-=T;
	}

	if(D[N]==1){
		dp[N]+=T;
	}


	//6.??????
	int X;
	for(int i=1;i<Q+1;i++){
		cin>>X;
		cout<<calc(X)<<endl;
	}

	return 0;
}

Measured memory_bytes: 6576
#include <cstdio>

int main(){
   int n;

   while(true){
        scanf("%d",&n);
        if(n == 0){
            break;
        }
        int min = 1000;
        int max = 0;
        int sum = 0;
        for(int i = 0;i < n;i++){
            int k;
            scanf("%d",&k);
            if(k <= min){
                min = k;
            }
            if(k >= max){
                max = k;
            }
            sum += k;
        }
        printf("%d\n",(sum - (max + min)) / (n - 2));
    };
}


Measured memory_bytes: 2584
import java.util.Scanner;

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

        String[] s = sc.nextLine().split(" ");
        Stack stack = new Stack();

        for (int i = 0; i < s.length; i++) {
            if (s[i].equals("+")) {
                int a = stack.pop();
                int b = stack.pop();
                stack.push(a + b);
            } else if (s[i].equals("-")) {
                int a = stack.pop();
                int b = stack.pop();
                stack.push(b - a);
            } else if (s[i].equals("*")) {
                int a = stack.pop();
                int b = stack.pop();
                stack.push(b * a);
            } else {
                int a = Integer.parseInt(s[i]);
                stack.push(a);
            }
        }

        System.out.println(stack.pop());
    }

    static class Stack {
        int[] S;
        int index;

        Stack() {
            S = new int[1000];
            index = 0;
        }

        void push(int x) {
            S[index++] = x;
        }

        int pop() {
            return S[--index];
        }
    }
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define MOD 1000000007
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;

int a,b,c,d;

signed main() {
    cin >> a >> b >> c >> d;
    while(true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }

    }
}




Measured memory_bytes: 3604
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
#define PI (acos(-1))


ll dp[51][51][2505];
ll a[51];
ll solve()
{

    ll n, x;
    cin >> n >> x;
    for(int i=0; i < n; i++){
        cin >> a[i];
    }

    dp[0][0][0] = 1;
    for(int i=0; i < n; i++){
        for(int j=0; j < n; j++){
            for(int k=0; k < 2501; k++){
                dp[i + 1][j][k] += dp[i][j][k];
                if(k - a[i] >= 0){
                    dp[i + 1][j + 1][k] += dp[i][j][k - a[i]];
                    }
                }
            }
        }
    

    ll ans = 0;
    for(int i=1; i < n + 1; i++){
        for(int j=1; j < 2501; j++){
            if( j % i == 0 && x == j / i){
                ans+=dp[n][i][j];
            }
        }
    }
    cout << ans << endl;

    return 0;
}

int main()
{
    //cout.precision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();
}


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

using namespace std;

vector<int> adj[100005];
int dp[100005];

int solve(int u)
{
	if (dp[u] != -1)
		return dp[u];
		
	int ans = 0;
	for (auto &v : adj[u])
		ans = max(ans, solve(v) + 1);

	return dp[u] = ans;
}

int main()
{
	#ifdef ME
		freopen("input.txt", "r", stdin);
	#endif
	int n, m;
	
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		adj[x].push_back(y);
	}
	memset(dp, -1, sizeof(dp));

	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans = max(ans, solve(i));

	cout << ans;

	return 0;
}


Measured memory_bytes: 8192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < n; i++){
			int outCount = 0;
			Ground gr = new Ground();
			while(true){
				String event = br.readLine();
				
				if(event.equals("OUT")){
					outCount++;
					if(outCount == 3){
						break;
					}
				}
				else if(event.equals("HIT")){
					gr.Hit();
					//gr.printPoint();
				}
				else if(event.equals("HOMERUN")){
					gr.HomeRun();
					//gr.printPoint();
				}
			}
			
			gr.printPoint();
		}
	}

}

class Ground {
	int[] base;
	int point;
	
	public Ground(){
		base = new int[3];
		Arrays.fill(base, 0);
		point = 0;
	}
	
	public void Hit(){
		if (base[2] == 1){
			point++;
		}
		
		base[2] = base[1];
		base[1] = base[0];
		base[0] = 1;
	}
	
	public void HomeRun(){
		for(int i = 0; i < 3 ; i++){
			point += base[i];
			base[i] = 0;
		}
		point++;
	}
	
	public void printPoint(){
		System.out.println(point);
	}
}

Measured memory_bytes: 24072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int N = sc.nextInt();
    long[] A = new long[N];
    long[] B = new long[N];
    int count = 0;
    for(int i = 0; i < N; i++){
       A[i] = sc.nextInt();
       B[i] = sc.nextInt();
    }

    long temp_dif;
    long temp_sum = 0;
    for(int i = N - 1; i >= 0; i--){
      A[i] += temp_sum;
      if( A[i] % B[i] != 0){

        temp_dif = B[i] - (A[i] % B[i]);
        temp_sum += temp_dif;
      }
    }


    System.out.println(temp_sum);
  }
}

Measured memory_bytes: 66556
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [f64; n],
    }
    let mut ans = 0f64;
    for i in 0..n {
        ans += 1. / a[i];
    }
    ans = 1. / ans;
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		
		int min=Integer.MAX_VALUE;
		min=Math.min(a+b, b+c);
		min=Math.min(min, c+a);
		System.out.println(min);
		
	}

}


Measured memory_bytes: 22996
#include <stdio.h>
int main(void){
  int i,j,n,taro_p=0,hana_p=0;
  char taro[101], hana[101];
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%s %s", taro, hana);
    for(j=0;;j++){
      if(taro[j] > hana[j]){
        taro_p += 3;
        break;
      }else if(taro[j] < hana[j]){
        hana_p += 3;
        break;
      }else if(taro[j] + hana[j] == 0){
        hana_p++;
        taro_p++;
        break;
      }
    }
  }
  printf("%d %d\n", taro_p , hana_p);
  return 0;
}
  


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

using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i = (a); i != (b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

ll gcd(ll a, ll b)
{
	while (b) a %= b, swap(a, b); return a; }



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int N;
	ll X;
	cin >> N >> X;
	ll g = 0;
	REP(i, N) {
		ll Y;
		cin >> Y;
		Y = abs(Y - X);
		g = gcd(g, Y);
	}
	cout << g << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
from math import gcd
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=[0]*n
    b=[0]*n
    for i in range(n):
        a[i],b[i]=map(int,readline().split())

    mod=1000000007
    d=dict()
    d[(1,0)]=[0,0]
    ans=1
    zeros=0
    for i in range(n):
        up=a[i]
        down=b[i]
        if up==0 and down==0:
            zeros+=1
        else:
            g=gcd(up,down)
            up//=g
            down//=g
            if up==0:
                down=1
            elif down==0:
                up==1
            elif down<0:
                down*=-1
                up*=-1

            if up==1 and down==0:
                d[(1,0)][0]+=1
            elif up==0 and down==1:
                d[(1,0)][1]+=1
            elif up>0:
                if (up,down) not in d and (-down,up) not in d:
                    d[(up,down)]=[1,0]
                elif (up,down) in d:
                    d[(up,down)][0]+=1
                else:
                    d[(-down,up)][1]+=1
            elif up<0:
                if (up,down) not in d and (down,-up) not in d:
                    d[(up,down)]=[1,0]
                elif (up,down) in d:
                    d[(up,down)][0]+=1
                else:
                    d[(down,-up)][1]+=1

    for v in d.values():
        ans*=pow(2,v[0])+pow(2,v[1])-1
        ans%=mod
    ans-=1
    ans+=zeros
    ans%=mod
    print(ans)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 79484